26 lines
515 B
Go
26 lines
515 B
Go
package json
|
|
|
|
import (
|
|
ejson "encoding/json"
|
|
|
|
"github.com/influxdata/telegraf/plugins"
|
|
)
|
|
|
|
type JsonSerializer struct {
|
|
}
|
|
|
|
func (s *JsonSerializer) Serialize(metric plugins.Metric) ([]byte, error) {
|
|
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 []byte{}, err
|
|
}
|
|
serialized = append(serialized, '\n')
|
|
|
|
return serialized, nil
|
|
}
|