1.7 KiB
1.7 KiB
Processor Plugins
This section is for developers who want to create a new processor plugin.
Processor Plugin Guidelines
- A processor must conform to the telegraf.Processor interface.
- Processors should call
processors.Add
in theirinit
function to register themselves. See below for a quick example. - To be available within Telegraf itself, plugins must add themselves to the
github.com/influxdata/telegraf/plugins/processors/all/all.go
file. - The
SampleConfig
function should return valid toml that describes how the processor can be configured. This is include in the output oftelegraf config
.
- The
SampleConfig
function should return valid toml that describes how the plugin can be configured. This is included intelegraf config
. Please consult the SampleConfig page for the latest style guidelines.
- The
Description
function should say in one line what this processor does.
Processor Plugin Example
package printer
// printer.go
import (
"fmt"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/processors"
)
type Printer struct {
}
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 {
fmt.Println(metric.String())
}
return in
}
func init() {
processors.Add("printer", func() telegraf.Processor {
return &Printer{}
})
}