Fix librato output support for uint and bool (#4151)

(cherry picked from commit e45822e2e2)
This commit is contained in:
Daniel Nelson 2018-05-15 15:54:20 -07:00 committed by Daniel Nelson
parent a9b0cc706b
commit e50f7f4bf8
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
1 changed files with 7 additions and 6 deletions

View File

@ -107,7 +107,6 @@ func (l *Librato) Write(metrics []telegraf.Metric) error {
for _, gauge := range gauges { for _, gauge := range gauges {
tempGauges = append(tempGauges, gauge) tempGauges = append(tempGauges, gauge)
log.Printf("D! Got a gauge: %v\n", gauge) log.Printf("D! Got a gauge: %v\n", gauge)
} }
} else { } else {
log.Printf("I! unable to build Gauge for %s, skipping\n", m.Name()) log.Printf("I! unable to build Gauge for %s, skipping\n", m.Name())
@ -234,16 +233,18 @@ func verifyValue(v interface{}) bool {
func (g *Gauge) setValue(v interface{}) error { func (g *Gauge) setValue(v interface{}) error {
switch d := v.(type) { switch d := v.(type) {
case int:
g.Value = float64(int(d))
case int32:
g.Value = float64(int32(d))
case int64: case int64:
g.Value = float64(int64(d)) g.Value = float64(int64(d))
case float32: case uint64:
g.Value = float64(d) g.Value = float64(d)
case float64: case float64:
g.Value = float64(d) g.Value = float64(d)
case bool:
if d {
g.Value = float64(1.0)
} else {
g.Value = float64(0.0)
}
default: default:
return fmt.Errorf("undeterminable type %+v", d) return fmt.Errorf("undeterminable type %+v", d)
} }