Add only valid field types in cassandra input (#4048)

This commit is contained in:
Daniel Nelson 2018-04-19 16:56:46 -07:00 committed by GitHub
parent 07760b2758
commit 18cfb3f295
1 changed files with 6 additions and 4 deletions

View File

@ -4,12 +4,13 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
) )
type JolokiaClient interface { type JolokiaClient interface {
@ -60,7 +61,8 @@ func newCassandraMetric(host string, metric string,
func addValuesAsFields(values map[string]interface{}, fields map[string]interface{}, func addValuesAsFields(values map[string]interface{}, fields map[string]interface{},
mname string) { mname string) {
for k, v := range values { for k, v := range values {
if v != nil { switch v.(type) {
case int64, float64, string, bool:
fields[mname+"_"+k] = v fields[mname+"_"+k] = v
} }
} }
@ -117,7 +119,7 @@ func (j javaMetric) addTagsFields(out map[string]interface{}) {
switch t := values.(type) { switch t := values.(type) {
case map[string]interface{}: case map[string]interface{}:
addValuesAsFields(values.(map[string]interface{}), fields, attribute) addValuesAsFields(values.(map[string]interface{}), fields, attribute)
case interface{}: case int64, float64, string, bool:
fields[attribute] = t fields[attribute] = t
} }
j.acc.AddFields(tokens["class"]+tokens["type"], fields, tags) j.acc.AddFields(tokens["class"]+tokens["type"], fields, tags)