Skip to content

Commit

Permalink
feat: adds EB support, logical changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhaev26 committed Jul 9, 2024
1 parent c77babd commit 4ee36aa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/zakhaev26/canario
go 1.22.0

require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
Expand Down
27 changes: 25 additions & 2 deletions pkg/canario/collect.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package canario

import (
"bytes"
"encoding/json"
"fmt"
"log"
"sync"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/zakhaev26/canario/internal/conf"
"github.com/zakhaev26/canario/internal/conf/parse"
"github.com/zakhaev26/canario/pkg/interfaces"
Expand Down Expand Up @@ -50,7 +54,27 @@ func (mb *MetricBatch) addMetricToBatch(incomingMetric MetricBufferUnitStructure

if len(mb.Buffer) >= BATCH_SIZE {
// make an api call with expo backoff..
mb.Buffer = nil
// go apiCall
mb.Buffer = mb.Buffer[:0]
}
}

func (mb *MetricBatch) sendMetrics() {

send := func() error {

var buf bytes.Buffer

_ = json.NewEncoder(&buf).Encode(mb.Buffer)
// Will be doing an API call to my servers
return nil
}

expBackoff := backoff.NewExponentialBackOff()
expBackoff.MaxElapsedTime = 1 * time.Minute

if err := backoff.Retry(send, expBackoff); err != nil {
log.Fatalf(err.Error()) // do some nice logging
}
}

Expand Down Expand Up @@ -90,7 +114,6 @@ func (c *Canario) RunPeriodicMetrics() {
}

c.mb.addMetricToBatch(thisMetric)
fmt.Println(c.mb.Buffer)
}
}

Expand Down

0 comments on commit 4ee36aa

Please sign in to comment.