Skip to content

Commit

Permalink
Fixed json serialization to make sure only value type supported by Op…
Browse files Browse the repository at this point in the history
…enTSDB are sent and made sure we send numbers un-quoted event though OpenTSDB API accepts them as this is not clean json.
  • Loading branch information
EricFortin authored and sparrc committed Oct 11, 2016
1 parent b702a97 commit 1f7a8fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions plugins/outputs/opentsdb/opentsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/opentsdb/opentsdb_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down

0 comments on commit 1f7a8fc

Please sign in to comment.