parent
df96958fb8
commit
869483617b
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
"github.com/influxdb/telegraf/duration"
|
||||
|
@ -36,6 +37,7 @@ type TimeSeries struct {
|
|||
type Metric struct {
|
||||
Metric string `json:"metric"`
|
||||
Points [1]Point `json:"points"`
|
||||
Host string `json:"host"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -68,8 +70,9 @@ func (d *Datadog) Write(points []*client.Point) error {
|
|||
}
|
||||
for index, pt := range points {
|
||||
metric := &Metric{
|
||||
Metric: pt.Name(),
|
||||
Metric: strings.Replace(pt.Name(), "_", ".", -1),
|
||||
Tags: buildTags(pt.Tags()),
|
||||
Host: pt.Tags()["host"],
|
||||
}
|
||||
if p, err := buildPoint(pt); err == nil {
|
||||
metric.Points[0] = p
|
||||
|
@ -87,10 +90,10 @@ func (d *Datadog) Write(points []*client.Point) error {
|
|||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
resp, err := d.client.Do(req)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error POSTing metrics, %s\n", err.Error())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 209 {
|
||||
return fmt.Errorf("received bad status code, %d\n", resp.StatusCode)
|
||||
|
|
Loading…
Reference in New Issue