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

This commit is contained in:
Pranay Kanwar 2018-02-21 07:02:18 +05:30 committed by Daniel Nelson
parent 3a4507866d
commit 6dd39616de
2 changed files with 23 additions and 2 deletions

View File

@ -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) {
} }
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 {
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")
} }

View File

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