forked from grafana/carbon-relay-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_wrapper.go
44 lines (38 loc) · 1.03 KB
/
metrics_wrapper.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
44
package main
import (
"fmt"
"github.com/Dieterbe/go-metrics"
"strings"
)
func Counter(key string) metrics.Counter {
c := metrics.NewCounter()
metrics.Register(expandKey(key), c)
return c
}
func Gauge(key string) metrics.Gauge {
g := metrics.NewGauge()
metrics.Register(expandKey(key), g)
return g
}
func Timer(key string) metrics.Timer {
//t := metrics.NewTimer()
//default is NewExpDecaySample(1028, 0.015)
//histogram: NewHistogram(NewExpDecaySample(1028, 0.015)),
histogram := metrics.NewHistogram(metrics.NewWindowSample())
meter := metrics.NewMeter()
t := metrics.NewCustomTimer(histogram, meter)
metrics.Register(expandKey(key), t)
return t
}
func Histogram(key string) metrics.Histogram {
h := metrics.NewHistogram(metrics.NewWindowSample())
metrics.Register(expandKey(key), h)
return h
}
func expandKey(key string) string {
if instance == "" {
panic("instance must be set in graphite expandKey!")
}
key = fmt.Sprintf("service=%s.instance=%s.%s", service, instance, key)
return strings.Replace(key, "=", "_is_", -1)
}