fix: datadog count metrics (#10979)

This commit is contained in:
Jimmy Rimmer 2022-04-27 15:04:34 -07:00 committed by GitHub
parent 5a71d03e63
commit eb791360c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -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

View File

@ -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
@ -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)