telegraf/plugins/processors/printer/printer.go

45 lines
846 B
Go
Raw Permalink Normal View History

package printer
import (
"fmt"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/processors"
"github.com/influxdata/telegraf/plugins/serializers"
"github.com/influxdata/telegraf/plugins/serializers/influx"
)
type Printer struct {
serializer serializers.Serializer
}
var sampleConfig = `
`
func (p *Printer) SampleConfig() string {
return sampleConfig
}
func (p *Printer) Description() string {
return "Print all metrics that pass through this filter."
}
func (p *Printer) Apply(in ...telegraf.Metric) []telegraf.Metric {
for _, metric := range in {
octets, err := p.serializer.Serialize(metric)
if err != nil {
continue
}
fmt.Println(octets)
}
return in
}
func init() {
processors.Add("printer", func() telegraf.Processor {
return &Printer{
serializer: influx.NewSerializer(),
}
})
}