From 8b8c64e7488c944fb6b7ba956be4329a69986689 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 20 Sep 2016 14:26:08 -0400 Subject: [PATCH] Fixed json serialization to make sure only value type supported by OpenTSDB are sent and made sure we send numbers un-quoted event though OpenTSDB API accepts them as this is not clean json. --- plugins/outputs/opentsdb/opentsdb.go | 11 +++++++---- plugins/outputs/opentsdb/opentsdb_http.go | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/outputs/opentsdb/opentsdb.go b/plugins/outputs/opentsdb/opentsdb.go index d7b3eb915..b3d9b4997 100644 --- a/plugins/outputs/opentsdb/opentsdb.go +++ b/plugins/outputs/opentsdb/opentsdb.go @@ -109,9 +109,12 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error { tags := cleanTags(m.Tags()) for fieldName, value := range m.Fields() { - metricValue, buildError := buildValue(value) - if buildError != nil { - fmt.Printf("OpenTSDB: %s\n", buildError.Error()) + switch value.(type) { + case int64: + case uint64: + case float64: + default: + fmt.Printf("OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value) continue } @@ -120,7 +123,7 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error { o.Prefix, m.Name(), fieldName)), Tags: tags, Timestamp: now, - Value: metricValue, + Value: value, } if err := http.sendDataPoint(metric); err != nil { diff --git a/plugins/outputs/opentsdb/opentsdb_http.go b/plugins/outputs/opentsdb/opentsdb_http.go index 27e4afdda..e2d25a82d 100644 --- a/plugins/outputs/opentsdb/opentsdb_http.go +++ b/plugins/outputs/opentsdb/opentsdb_http.go @@ -16,7 +16,7 @@ import ( type HttpMetric struct { Metric string `json:"metric"` Timestamp int64 `json:"timestamp"` - Value string `json:"value"` + Value interface{} `json:"value"` Tags map[string]string `json:"tags"` }