Reputation: 537
I am using "github.com/cactus/go-statsd-client/statsd"
library to post stats
NewBufferedClient
client.Gauge("metric_name", 0, 1)
client.GaugeDelta("metric_name", 1, 1)
and than after some logic client.GaugeDelta("metric_name, -1, 1)
. This can be called multiple times at many workers.As I understand it should end up with metric_name
at AWS CloudWatch agent
set up at 0, but it actually creates a negative values metric and an error that it cannot be negative.
$ go.mod
...
github.com/cactus/go-statsd-client v0.0.0-00010101000000-000000000000
...
$ content.go
import (
...
"github.com/cactus/go-statsd-client/statsd"
...
)
func init() {
var err error
cwclient, err = statsd.NewBufferedClient(host, namespace, time.Second, 0)
if err != nil {
log.Fatal(err)
}
cwclient.Gauge("metric", 0, 1)
}
type Content struct {
...
}
func NewContent() *Content {
...
}
func (self *Content) Work() {
self.cwclient.GaugeDelta("metric", 1, 1)
err := self.work()
if err != nil {
// Do something
}
self.cwclient.GaugeDelta("metric", -1, 1)
}
func (self *Content) work() (err error) {
...
}
Upvotes: 1
Views: 27