committed by
Cameron Sparr
parent
d6b5f3efe6
commit
d66d66e74b
27
plugins/serializers/json/json.go
Normal file
27
plugins/serializers/json/json.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
ejson "encoding/json"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
)
|
||||
|
||||
type JsonSerializer struct {
|
||||
}
|
||||
|
||||
func (s *JsonSerializer) Serialize(metric telegraf.Metric) ([]string, error) {
|
||||
out := []string{}
|
||||
|
||||
m := make(map[string]interface{})
|
||||
m["tags"] = metric.Tags()
|
||||
m["fields"] = metric.Fields()
|
||||
m["name"] = metric.Name()
|
||||
m["timestamp"] = metric.UnixNano() / 1000000000
|
||||
serialized, err := ejson.Marshal(m)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
out = append(out, string(serialized))
|
||||
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user