-
Notifications
You must be signed in to change notification settings - Fork 1
/
type_gauge.go
52 lines (41 loc) · 975 Bytes
/
type_gauge.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
45
46
47
48
49
50
51
52
package main
func init() {
mt := metricType{
create: func() metric { return &gaugeMetric{} },
channels: []string{"gauge"},
defaults: []float64{0},
persist: []bool{true},
aggregator: func([]string) aggregator { return &gaugeAggregator{} },
}
registerMetricType(Gauge, mt)
}
type gaugeMetric struct {
value float64
}
func (m *gaugeMetric) init(data []float64) {
m.value = data[0]
}
func (m *gaugeMetric) inject(metric *Metric) {
m.value = metric.Value
}
func (m *gaugeMetric) tick() []float64 {
return []float64{m.value}
}
func (m *gaugeMetric) flush() []float64 {
return []float64{m.value}
}
type gaugeAggregator struct {
value float64
}
func (aggr *gaugeAggregator) channels() []int {
return []int{0}
}
func (aggr *gaugeAggregator) init(data []float64) {
aggr.value = data[0]
}
func (aggr *gaugeAggregator) put(data []float64) {
aggr.value = data[0]
}
func (aggr *gaugeAggregator) get() []float64 {
return []float64{aggr.value}
}