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.
This commit is contained in:
parent
b702a9758b
commit
1f7a8fceef
|
@ -109,9 +109,12 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error {
|
||||||
tags := cleanTags(m.Tags())
|
tags := cleanTags(m.Tags())
|
||||||
|
|
||||||
for fieldName, value := range m.Fields() {
|
for fieldName, value := range m.Fields() {
|
||||||
metricValue, buildError := buildValue(value)
|
switch value.(type) {
|
||||||
if buildError != nil {
|
case int64:
|
||||||
fmt.Printf("OpenTSDB: %s\n", buildError.Error())
|
case uint64:
|
||||||
|
case float64:
|
||||||
|
default:
|
||||||
|
fmt.Printf("OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +123,7 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error {
|
||||||
o.Prefix, m.Name(), fieldName)),
|
o.Prefix, m.Name(), fieldName)),
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Timestamp: now,
|
Timestamp: now,
|
||||||
Value: metricValue,
|
Value: value,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := http.sendDataPoint(metric); err != nil {
|
if err := http.sendDataPoint(metric); err != nil {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
type HttpMetric struct {
|
type HttpMetric struct {
|
||||||
Metric string `json:"metric"`
|
Metric string `json:"metric"`
|
||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
Value string `json:"value"`
|
Value interface{} `json:"value"`
|
||||||
Tags map[string]string `json:"tags"`
|
Tags map[string]string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue