Skip to content
Snippets Groups Projects
Commit b355536b authored by Pranay Kanwar's avatar Pranay Kanwar Committed by Daniel Nelson
Browse files

Convert boolean metric values to float in datadog output (#3804)

parent e988c830
No related branches found
No related tags found
No related merge requests found
...@@ -97,7 +97,7 @@ func (d *Datadog) Write(metrics []telegraf.Metric) error { ...@@ -97,7 +97,7 @@ func (d *Datadog) Write(metrics []telegraf.Metric) error {
metricCounter++ metricCounter++
} }
} else { } else {
log.Printf("I! unable to build Metric for %s, skipping\n", m.Name()) log.Printf("I! unable to build Metric for %s due to error '%v', skipping\n", m.Name(), err)
} }
} }
...@@ -150,7 +150,7 @@ func buildMetrics(m telegraf.Metric) (map[string]Point, error) { ...@@ -150,7 +150,7 @@ func buildMetrics(m telegraf.Metric) (map[string]Point, error) {
} }
var p Point var p Point
if err := p.setValue(v); err != nil { if err := p.setValue(v); err != nil {
return ms, fmt.Errorf("unable to extract value from Fields, %s", err.Error()) return ms, fmt.Errorf("unable to extract value from Fields %v error %v", k, err.Error())
} }
p[0] = float64(m.Time().Unix()) p[0] = float64(m.Time().Unix())
ms[k] = p ms[k] = p
...@@ -189,6 +189,11 @@ func (p *Point) setValue(v interface{}) error { ...@@ -189,6 +189,11 @@ func (p *Point) setValue(v interface{}) error {
p[1] = float64(d) p[1] = float64(d)
case float64: case float64:
p[1] = float64(d) p[1] = float64(d)
case bool:
p[1] = float64(0)
if d {
p[1] = float64(1)
}
default: default:
return fmt.Errorf("undeterminable type") return fmt.Errorf("undeterminable type")
} }
......
...@@ -152,6 +152,22 @@ func TestBuildPoint(t *testing.T) { ...@@ -152,6 +152,22 @@ func TestBuildPoint(t *testing.T) {
}, },
nil, nil,
}, },
{
testutil.TestMetric(bool(true), "test7"),
Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
1.0,
},
nil,
},
{
testutil.TestMetric(bool(false), "test8"),
Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
0.0,
},
nil,
},
} }
for _, tt := range tagtests { for _, tt := range tagtests {
pt, err := buildMetrics(tt.ptIn) pt, err := buildMetrics(tt.ptIn)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment