JSON does not support values NaN and Inf (#7908)
This commit is contained in:
parent
198f92be41
commit
2e751d0b54
|
|
@ -3,6 +3,7 @@ package opentsdb
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -136,10 +137,14 @@ 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() {
|
||||||
switch value.(type) {
|
switch fv := value.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
case uint64:
|
case uint64:
|
||||||
case float64:
|
case float64:
|
||||||
|
// JSON does not support these special values
|
||||||
|
if math.IsNaN(fv) || math.IsInf(fv, 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
log.Printf("D! OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
|
log.Printf("D! OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
|
||||||
continue
|
continue
|
||||||
|
|
@ -181,10 +186,14 @@ func (o *OpenTSDB) WriteTelnet(metrics []telegraf.Metric, u *url.URL) error {
|
||||||
tags := ToLineFormat(cleanTags(m.Tags()))
|
tags := ToLineFormat(cleanTags(m.Tags()))
|
||||||
|
|
||||||
for fieldName, value := range m.Fields() {
|
for fieldName, value := range m.Fields() {
|
||||||
switch value.(type) {
|
switch fv := value.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
case uint64:
|
case uint64:
|
||||||
case float64:
|
case float64:
|
||||||
|
// JSON does not support these special values
|
||||||
|
if math.IsNaN(fv) || math.IsInf(fv, 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
log.Printf("D! OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
|
log.Printf("D! OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue