Skip to content

Commit 54c9ba7

Browse files
committed
Update documentation for Gauge & Counters
1 parent b18d375 commit 54c9ba7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- [#1694](https://github.com/influxdata/telegraf/pull/1694): Adding Gauge and Counter metric types.
78
- [#1606](https://github.com/influxdata/telegraf/pull/1606): Remove carraige returns from exec plugin output on Windows
89
- [#1674](https://github.com/influxdata/telegraf/issues/1674): elasticsearch input: configurable timeout.
910
- [#1607](https://github.com/influxdata/telegraf/pull/1607): Massage metric names in Instrumental output plugin

CONTRIBUTING.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Assuming you can already build the project, run these in the telegraf directory:
3232

3333
1. `go get github.com/sparrc/gdm`
3434
1. `gdm restore`
35-
1. `gdm save`
35+
1. `GOOS=linux gdm save`
3636

3737
## Input Plugins
3838

@@ -84,9 +84,9 @@ func (s *Simple) SampleConfig() string {
8484

8585
func (s *Simple) Gather(acc telegraf.Accumulator) error {
8686
if s.Ok {
87-
acc.Add("state", "pretty good", nil)
87+
acc.AddFields("state", map[string]interface{}{"value": "pretty good"}, nil)
8888
} else {
89-
acc.Add("state", "not great", nil)
89+
acc.AddFields("state", map[string]interface{}{"value": "not great"}, nil)
9090
}
9191

9292
return nil
@@ -97,6 +97,13 @@ func init() {
9797
}
9898
```
9999

100+
## Adding Typed Metrics
101+
102+
In addition the the `AddFields` function, the accumulator also supports an
103+
`AddGauge` and `AddCounter` function. These functions are for adding _typed_
104+
metrics. Metric types are ignored for the InfluxDB output, but can be used
105+
for other outputs, such as [prometheus](https://prometheus.io/docs/concepts/metric_types/).
106+
100107
## Input Plugins Accepting Arbitrary Data Formats
101108

102109
Some input plugins (such as

accumulator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ package telegraf
22

33
import "time"
44

5+
// Accumulator is an interface for "accumulating" metrics from input plugin(s).
6+
// The metrics are sent down a channel shared between all input plugins and then
7+
// flushed on the configured flush_interval.
58
type Accumulator interface {
9+
// AddFields adds a metric to the accumulator with the given measurement
10+
// name, fields, and tags (and timestamp). If a timestamp is not provided,
11+
// then the accumulator sets it to "now".
612
// Create a point with a value, decorating it with tags
713
// NOTE: tags is expected to be owned by the caller, don't mutate
814
// it after passing to Add.
@@ -11,15 +17,13 @@ type Accumulator interface {
1117
tags map[string]string,
1218
t ...time.Time)
1319

14-
// AddGauge is the same as AddFields, but will add the metric as a "Gauge"
15-
// type
20+
// AddGauge is the same as AddFields, but will add the metric as a "Gauge" type
1621
AddGauge(measurement string,
1722
fields map[string]interface{},
1823
tags map[string]string,
1924
t ...time.Time)
2025

21-
// AddCounter is the same as AddFields, but will add the metric as a "Counter"
22-
// type
26+
// AddCounter is the same as AddFields, but will add the metric as a "Counter" type
2327
AddCounter(measurement string,
2428
fields map[string]interface{},
2529
tags map[string]string,

0 commit comments

Comments
 (0)