-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_gauge64.go
43 lines (36 loc) · 1022 Bytes
/
m_gauge64.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 metrics
import (
client "github.com/influxdata/influxdb1-client"
"github.com/rcrowley/go-metrics"
)
// GaugeFloat64 implements go-metrics.GaugeFloat64 and possibly adds a bit functionality.
type GaugeFloat64 interface {
metrics.GaugeFloat64
}
func newGaugeFloat64(name string, options ...Option) *gaugeFloat64 {
m := newMetric(name, options...)
m.suffix = suffGauge
// was a metric provided? if not create new one.
mtrx, ok := m.metric.(metrics.GaugeFloat64)
if !ok {
mtrx = metrics.NewGaugeFloat64()
}
t := &gaugeFloat64{
baseMetric: *m,
GaugeFloat64: mtrx,
fieldName: m.name + m.suffix,
}
return m.register(t).(*gaugeFloat64)
}
type gaugeFloat64 struct {
metrics.GaugeFloat64
baseMetric
fieldName string
}
// AddPoints adds points to be written to the db.
func (s *gaugeFloat64) AddPoints(pts []client.Point) []client.Point {
fields := map[string]interface{}{
s.fieldName: s.GaugeFloat64.Snapshot().Value(),
}
return append(pts, getPoint(s.measurement, fields, s.tags))
}