Package list golang-github-go-kit-kit / 2e19bd3
metrics: Gauge becomes float64 Peter Bourgon 6 years ago
6 changed file(s) with 21 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
4141 func (c *counter) Add(delta uint64) { c.v.Add(int64(delta)) }
4242
4343 type gauge struct {
44 v *expvar.Int
44 v *expvar.Float
4545 }
4646
4747 // NewGauge returns a new Gauge backed by an expvar with the given name.
4848 // Fields are ignored.
4949 func NewGauge(name string) metrics.Gauge {
50 return &gauge{expvar.NewInt(name)}
50 return &gauge{expvar.NewFloat(name)}
5151 }
5252
5353 func (g *gauge) With(metrics.Field) metrics.Gauge { return g }
5454
55 func (g *gauge) Add(delta int64) { g.v.Add(delta) }
55 func (g *gauge) Add(delta float64) { g.v.Add(delta) }
5656
57 func (g *gauge) Set(value int64) { g.v.Set(value) }
57 func (g *gauge) Set(value float64) { g.v.Set(value) }
5858
5959 type histogram struct {
6060 mu sync.Mutex
9999 }
100100
101101 for q, gauge := range h.gauges {
102 gauge.Set(h.hist.Current.ValueAtQuantile(float64(q)))
102 gauge.Set(float64(h.hist.Current.ValueAtQuantile(float64(q))))
103103 }
104104 }
105105
1313 }
1414
1515 // Gauge captures instantaneous measurements of something using signed, 64-bit
16 // integers. The value does not need to be monotonic.
16 // floats. The value does not need to be monotonic.
1717 type Gauge interface {
1818 With(Field) Gauge
19 Set(value int64)
20 Add(delta int64)
19 Set(value float64)
20 Add(delta float64)
2121 }
2222
2323 // Histogram tracks the distribution of a stream of values (e.g. the number of
4343 return next
4444 }
4545
46 func (g multiGauge) Set(value int64) {
46 func (g multiGauge) Set(value float64) {
4747 for _, gauge := range g {
4848 gauge.Set(value)
4949 }
5050 }
5151
52 func (g multiGauge) Add(delta int64) {
52 func (g multiGauge) Add(delta float64) {
5353 for _, gauge := range g {
5454 gauge.Add(delta)
5555 }
102102 }
103103 }
104104
105 func (g prometheusGauge) Set(value int64) {
106 g.GaugeVec.With(prometheus.Labels(g.Pairs)).Set(float64(value))
105 func (g prometheusGauge) Set(value float64) {
106 g.GaugeVec.With(prometheus.Labels(g.Pairs)).Set(value)
107107 }
108108
109 func (g prometheusGauge) Add(delta int64) {
110 g.GaugeVec.With(prometheus.Labels(g.Pairs)).Add(float64(delta))
109 func (g prometheusGauge) Add(delta float64) {
110 g.GaugeVec.With(prometheus.Labels(g.Pairs)).Add(delta)
111111 }
112112
113113 type prometheusHistogram struct {
6060
6161 func (g statsdGauge) With(metrics.Field) metrics.Gauge { return g }
6262
63 func (g statsdGauge) Add(delta int64) {
63 func (g statsdGauge) Add(delta float64) {
6464 // https://github.com/etsy/statsd/blob/master/docs/metric_types.md#gauges
6565 sign := "+"
6666 if delta < 0 {
6767 sign, delta = "-", -delta
6868 }
69 g <- fmt.Sprintf("%s%d|g", sign, delta)
69 g <- fmt.Sprintf("%s%f|g", sign, delta)
7070 }
7171
72 func (g statsdGauge) Set(value int64) {
73 g <- fmt.Sprintf("%d|g", value)
72 func (g statsdGauge) Set(value float64) {
73 g <- fmt.Sprintf("%f|g", value)
7474 }
7575
7676 type statsdHistogram chan string
4141 runtime.Gosched() // yield to buffer write
4242 ch <- time.Now() // signal flush
4343 runtime.Gosched() // yield to flush
44 if want, have := "test_statsd_gauge:+1|g\n", buf.String(); want != have {
44 if want, have := "test_statsd_gauge:+1.000000|g\n", buf.String(); want != have {
4545 t.Errorf("want %q, have %q", want, have)
4646 }
4747
5151 runtime.Gosched()
5252 ch <- time.Now()
5353 runtime.Gosched()
54 if want, have := "test_statsd_gauge:-2|g\n", buf.String(); want != have {
54 if want, have := "test_statsd_gauge:-2.000000|g\n", buf.String(); want != have {
5555 t.Errorf("want %q, have %q", want, have)
5656 }
5757
6161 runtime.Gosched()
6262 ch <- time.Now()
6363 runtime.Gosched()
64 if want, have := "test_statsd_gauge:3|g\n", buf.String(); want != have {
64 if want, have := "test_statsd_gauge:3.000000|g\n", buf.String(); want != have {
6565 t.Errorf("want %q, have %q", want, have)
6666 }
6767 }