Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: datadog count metrics #10979

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ 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