-
Notifications
You must be signed in to change notification settings - Fork 183
/
accumulator.go
65 lines (54 loc) · 2.42 KB
/
accumulator.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
53
54
55
56
57
58
59
60
61
62
63
64
65
package accumulator
import (
"time"
"github.com/signalfx/golib/datapoint"
"github.com/signalfx/signalfx-agent/internal/monitors/telegraf/common/emitter"
)
// Accumulator is an interface used to accumulate telegraf measurements from
// Telegraf plugins.
type Accumulator struct {
emit emitter.Emitter
}
// AddFields receives a measurement with tags and a time stamp to the accumulator.
// Measurements are passed to the Accumulator's Emitter.
func (ac *Accumulator) AddFields(measurement string, fields map[string]interface{},
tags map[string]string, t ...time.Time) {
ac.emit.Add(measurement, fields, tags, datapoint.Gauge, "untyped", t...)
}
// AddGauge receives a measurement as a "Gauge" with tags and a time stamp to
// the accumulator. Measurements are passed to the Accumulator's Emitter.
func (ac *Accumulator) AddGauge(measurement string, fields map[string]interface{},
tags map[string]string, t ...time.Time) {
ac.emit.Add(measurement, fields, tags, datapoint.Gauge, "", t...)
}
// AddCounter receives a measurement as a "Counter" with tags and a time stamp
// to the accumulator. Measurements are passed to the Accumulator's Emitter.
func (ac *Accumulator) AddCounter(measurement string, fields map[string]interface{},
tags map[string]string, t ...time.Time) {
ac.emit.Add(measurement, fields, tags, datapoint.Counter, "", t...)
}
// AddSummary receives a measurement as a "Counter" with tags and a time stamp
// to the accumulator. Measurements are passed to the Accumulator's Emitter.
func (ac *Accumulator) AddSummary(measurement string, fields map[string]interface{},
tags map[string]string, t ...time.Time) {
ac.emit.Add(measurement, fields, tags, datapoint.Gauge, "summary", t...)
}
// AddHistogram receives a measurement as a "Counter" with tags and a time stamp
// to the accumulator. Measurements are passed to the Accumulator's Emitter.
func (ac *Accumulator) AddHistogram(measurement string, fields map[string]interface{},
tags map[string]string, t ...time.Time) {
ac.emit.Add(measurement, fields, tags, datapoint.Gauge, "histogram", t...)
}
// SetPrecision - SignalFx does not implement this
func (ac *Accumulator) SetPrecision(precision, interval time.Duration) {
}
// AddError - log an error returned by the plugin
func (ac *Accumulator) AddError(err error) {
ac.emit.AddError(err)
}
// NewAccumulator returns a pointer to an Accumulator
func NewAccumulator(e emitter.Emitter) *Accumulator {
return &Accumulator{
emit: e,
}
}