-
Notifications
You must be signed in to change notification settings - Fork 4
/
metric_statsd.go
43 lines (33 loc) · 998 Bytes
/
metric_statsd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package owl
import "github.com/cactus/go-statsd-client/statsd"
var (
statsdClient statsd.Statter
statsdStatPrefix string
)
func initMetricStatsd() error {
var err error
if statsdClient, err = statsd.NewClient(config.Metric.StatsdUrl, config.AppName); err != nil {
useMetric = false
return Error("owl: cannot instantiate client to StatsD proxy (%s): %s", config.Metric.StatsdUrl, err)
}
statsdStatPrefix = config.AppName + "."
return nil
}
func metricIncStatsd(stat string, value int64) {
if !useMetric || statsdClient == nil {
return
}
err := statsdClient.Inc(statsdStatPrefix+stat, value, 1.0)
if err != nil {
Warning("owl: cannot increment metric %s of %d in StatsD: %s", stat, value, err)
}
}
func metricGaugeStatsd(stat string, value int64) {
if !useMetric || statsdClient == nil {
return
}
err := statsdClient.Gauge(statsdStatPrefix+stat, value, 1.0)
if err != nil {
Warning("owl: cannot gauge metric %s with %s in StatsD: %s", stat, value, err)
}
}