|
@@ -1,13 +1,14 @@
|
|
|
-package metrics
|
|
|
|
|
|
|
+// Metrics output to StatHat.
|
|
|
|
|
+package stathat
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
-
|
|
|
|
|
|
|
+ "github.com/rcrowley/go-metrics"
|
|
|
|
|
+ "github.com/stathat/go"
|
|
|
"log"
|
|
"log"
|
|
|
"time"
|
|
"time"
|
|
|
- "github.com/stathat/go"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-func Stathat(r Registry, d time.Duration, userkey string) {
|
|
|
|
|
|
|
+func Stathat(r metrics.Registry, d time.Duration, userkey string) {
|
|
|
for {
|
|
for {
|
|
|
if err := sh(r, userkey); nil != err {
|
|
if err := sh(r, userkey); nil != err {
|
|
|
log.Println(err)
|
|
log.Println(err)
|
|
@@ -16,14 +17,14 @@ func Stathat(r Registry, d time.Duration, userkey string) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func sh(r Registry, userkey string) error {
|
|
|
|
|
|
|
+func sh(r metrics.Registry, userkey string) error {
|
|
|
r.Each(func(name string, i interface{}) {
|
|
r.Each(func(name string, i interface{}) {
|
|
|
switch m := i.(type) {
|
|
switch m := i.(type) {
|
|
|
- case Counter:
|
|
|
|
|
|
|
+ case metrics.Counter:
|
|
|
stathat.PostEZCount(name, userkey, int(m.Count()))
|
|
stathat.PostEZCount(name, userkey, int(m.Count()))
|
|
|
- case Gauge:
|
|
|
|
|
|
|
+ case metrics.Gauge:
|
|
|
stathat.PostEZValue(name, userkey, float64(m.Value()))
|
|
stathat.PostEZValue(name, userkey, float64(m.Value()))
|
|
|
- case Histogram:
|
|
|
|
|
|
|
+ case metrics.Histogram:
|
|
|
ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
|
ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
|
|
stathat.PostEZCount(name+".count", userkey, int(m.Count()))
|
|
stathat.PostEZCount(name+".count", userkey, int(m.Count()))
|
|
|
stathat.PostEZValue(name+".min", userkey, float64(m.Min()))
|
|
stathat.PostEZValue(name+".min", userkey, float64(m.Min()))
|
|
@@ -35,13 +36,13 @@ func sh(r Registry, userkey string) error {
|
|
|
stathat.PostEZValue(name+".95-percentile", userkey, float64(ps[2]))
|
|
stathat.PostEZValue(name+".95-percentile", userkey, float64(ps[2]))
|
|
|
stathat.PostEZValue(name+".99-percentile", userkey, float64(ps[3]))
|
|
stathat.PostEZValue(name+".99-percentile", userkey, float64(ps[3]))
|
|
|
stathat.PostEZValue(name+".999-percentile", userkey, float64(ps[4]))
|
|
stathat.PostEZValue(name+".999-percentile", userkey, float64(ps[4]))
|
|
|
- case Meter:
|
|
|
|
|
|
|
+ case metrics.Meter:
|
|
|
stathat.PostEZCount(name+".count", userkey, int(m.Count()))
|
|
stathat.PostEZCount(name+".count", userkey, int(m.Count()))
|
|
|
stathat.PostEZValue(name+".one-minute", userkey, float64(m.Rate1()))
|
|
stathat.PostEZValue(name+".one-minute", userkey, float64(m.Rate1()))
|
|
|
stathat.PostEZValue(name+".five-minute", userkey, float64(m.Rate5()))
|
|
stathat.PostEZValue(name+".five-minute", userkey, float64(m.Rate5()))
|
|
|
stathat.PostEZValue(name+".fifteen-minute", userkey, float64(m.Rate15()))
|
|
stathat.PostEZValue(name+".fifteen-minute", userkey, float64(m.Rate15()))
|
|
|
stathat.PostEZValue(name+".mean", userkey, float64(m.RateMean()))
|
|
stathat.PostEZValue(name+".mean", userkey, float64(m.RateMean()))
|
|
|
- case Timer:
|
|
|
|
|
|
|
+ case metrics.Timer:
|
|
|
ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
|
ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
|
|
stathat.PostEZCount(name+".count", userkey, int(m.Count()))
|
|
stathat.PostEZCount(name+".count", userkey, int(m.Count()))
|
|
|
stathat.PostEZValue(name+".min", userkey, float64(m.Min()))
|
|
stathat.PostEZValue(name+".min", userkey, float64(m.Min()))
|
|
@@ -58,7 +59,6 @@ func sh(r Registry, userkey string) error {
|
|
|
stathat.PostEZValue(name+".fifteen-minute", userkey, float64(m.Rate15()))
|
|
stathat.PostEZValue(name+".fifteen-minute", userkey, float64(m.Rate15()))
|
|
|
stathat.PostEZValue(name+".mean", userkey, float64(m.RateMean()))
|
|
stathat.PostEZValue(name+".mean", userkey, float64(m.RateMean()))
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
})
|
|
})
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|