diff --git a/metrics/expvar/expvar.go b/metrics/expvar/expvar.go index ba8624b..eba74c9 100644 --- a/metrics/expvar/expvar.go +++ b/metrics/expvar/expvar.go @@ -42,20 +42,20 @@ func (c *counter) Add(delta uint64) { c.v.Add(int64(delta)) } type gauge struct { - v *expvar.Int + v *expvar.Float } // NewGauge returns a new Gauge backed by an expvar with the given name. // Fields are ignored. func NewGauge(name string) metrics.Gauge { - return &gauge{expvar.NewInt(name)} + return &gauge{expvar.NewFloat(name)} } func (g *gauge) With(metrics.Field) metrics.Gauge { return g } -func (g *gauge) Add(delta int64) { g.v.Add(delta) } +func (g *gauge) Add(delta float64) { g.v.Add(delta) } -func (g *gauge) Set(value int64) { g.v.Set(value) } +func (g *gauge) Set(value float64) { g.v.Set(value) } type histogram struct { mu sync.Mutex @@ -100,7 +100,7 @@ } for q, gauge := range h.gauges { - gauge.Set(h.hist.Current.ValueAtQuantile(float64(q))) + gauge.Set(float64(h.hist.Current.ValueAtQuantile(float64(q)))) } } diff --git a/metrics/metrics.go b/metrics/metrics.go index e76660f..49e93d3 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -14,11 +14,11 @@ } // Gauge captures instantaneous measurements of something using signed, 64-bit -// integers. The value does not need to be monotonic. +// floats. The value does not need to be monotonic. type Gauge interface { With(Field) Gauge - Set(value int64) - Add(delta int64) + Set(value float64) + Add(delta float64) } // Histogram tracks the distribution of a stream of values (e.g. the number of diff --git a/metrics/multi.go b/metrics/multi.go index 66c8074..b3990bd 100644 --- a/metrics/multi.go +++ b/metrics/multi.go @@ -44,13 +44,13 @@ return next } -func (g multiGauge) Set(value int64) { +func (g multiGauge) Set(value float64) { for _, gauge := range g { gauge.Set(value) } } -func (g multiGauge) Add(delta int64) { +func (g multiGauge) Add(delta float64) { for _, gauge := range g { gauge.Add(delta) } diff --git a/metrics/prometheus/prometheus.go b/metrics/prometheus/prometheus.go index 7187413..87ef4eb 100644 --- a/metrics/prometheus/prometheus.go +++ b/metrics/prometheus/prometheus.go @@ -103,12 +103,12 @@ } } -func (g prometheusGauge) Set(value int64) { - g.GaugeVec.With(prometheus.Labels(g.Pairs)).Set(float64(value)) +func (g prometheusGauge) Set(value float64) { + g.GaugeVec.With(prometheus.Labels(g.Pairs)).Set(value) } -func (g prometheusGauge) Add(delta int64) { - g.GaugeVec.With(prometheus.Labels(g.Pairs)).Add(float64(delta)) +func (g prometheusGauge) Add(delta float64) { + g.GaugeVec.With(prometheus.Labels(g.Pairs)).Add(delta) } type prometheusHistogram struct { diff --git a/metrics/statsd/statsd.go b/metrics/statsd/statsd.go index 5f091fa..8771a8e 100644 --- a/metrics/statsd/statsd.go +++ b/metrics/statsd/statsd.go @@ -61,17 +61,17 @@ func (g statsdGauge) With(metrics.Field) metrics.Gauge { return g } -func (g statsdGauge) Add(delta int64) { +func (g statsdGauge) Add(delta float64) { // https://github.com/etsy/statsd/blob/master/docs/metric_types.md#gauges sign := "+" if delta < 0 { sign, delta = "-", -delta } - g <- fmt.Sprintf("%s%d|g", sign, delta) + g <- fmt.Sprintf("%s%f|g", sign, delta) } -func (g statsdGauge) Set(value int64) { - g <- fmt.Sprintf("%d|g", value) +func (g statsdGauge) Set(value float64) { + g <- fmt.Sprintf("%f|g", value) } type statsdHistogram chan string diff --git a/metrics/statsd/statsd_test.go b/metrics/statsd/statsd_test.go index d0a2ff0..46a2380 100644 --- a/metrics/statsd/statsd_test.go +++ b/metrics/statsd/statsd_test.go @@ -42,7 +42,7 @@ runtime.Gosched() // yield to buffer write ch <- time.Now() // signal flush runtime.Gosched() // yield to flush - if want, have := "test_statsd_gauge:+1|g\n", buf.String(); want != have { + if want, have := "test_statsd_gauge:+1.000000|g\n", buf.String(); want != have { t.Errorf("want %q, have %q", want, have) } @@ -52,7 +52,7 @@ runtime.Gosched() ch <- time.Now() runtime.Gosched() - if want, have := "test_statsd_gauge:-2|g\n", buf.String(); want != have { + if want, have := "test_statsd_gauge:-2.000000|g\n", buf.String(); want != have { t.Errorf("want %q, have %q", want, have) } @@ -62,7 +62,7 @@ runtime.Gosched() ch <- time.Now() runtime.Gosched() - if want, have := "test_statsd_gauge:3|g\n", buf.String(); want != have { + if want, have := "test_statsd_gauge:3.000000|g\n", buf.String(); want != have { t.Errorf("want %q, have %q", want, have) } }