Skip to content

Commit

Permalink
fix: datadog count metrics (influxdata#10979)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrimmer-housecallpro committed Apr 27, 2022
1 parent 5a71d03 commit eb79136
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
6 changes: 6 additions & 0 deletions plugins/outputs/datadog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ field key with a `.` character.
Field values are converted to floating point numbers. Strings and floats that
cannot be sent over JSON, namely NaN and Inf, are ignored.

We do not send `Rate` types. Counts are sent as `count`, with an
interval hard-coded to 1. Note that this behavior does *not* play
super-well if running simultaneously with current Datadog agents; they
will attempt to change to `Rate` with `interval=10`. We prefer this
method, however, as it reflects the raw data more accurately.

[metrics]: https://docs.datadoghq.com/api/v1/metrics/#submit-metrics
[apikey]: https://app.datadoghq.com/account/settings#api
27 changes: 20 additions & 7 deletions plugins/outputs/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ type TimeSeries struct {
}

type Metric struct {
Metric string `json:"metric"`
Points [1]Point `json:"points"`
Host string `json:"host"`
Tags []string `json:"tags,omitempty"`
Metric string `json:"metric"`
Points [1]Point `json:"points"`
Host string `json:"host"`
Type string `json:"type,omitempty"`
Tags []string `json:"tags,omitempty"`
Interval int64 `json:"interval"`
}

type Point [2]float64
Expand Down Expand Up @@ -85,10 +87,21 @@ func (d *Datadog) Write(metrics []telegraf.Metric) error {
} else {
dname = m.Name() + "." + fieldName
}
var tname string
switch m.Type() {
case telegraf.Counter:
tname = "count"
case telegraf.Gauge:
tname = "gauge"
default:
tname = ""
}
metric := &Metric{
Metric: dname,
Tags: metricTags,
Host: host,
Metric: dname,
Tags: metricTags,
Host: host,
Type: tname,
Interval: 1,
}
metric.Points[0] = dogM
tempSeries = append(tempSeries, metric)
Expand Down

0 comments on commit eb79136

Please sign in to comment.