github.com/influxdata/telegraf@v1.30.3/processor.go (about) 1 package telegraf 2 3 // Processor is a processor plugin interface for defining new inline processors. 4 // these are extremely efficient and should be used over StreamingProcessor if 5 // you do not need asynchronous metric writes. 6 type Processor interface { 7 PluginDescriber 8 9 // Apply the filter to the given metric. 10 Apply(in ...Metric) []Metric 11 } 12 13 // StreamingProcessor is a processor that can take in a stream of messages 14 type StreamingProcessor interface { 15 PluginDescriber 16 17 // Start is called once when the plugin starts; it is only called once per 18 // plugin instance, and never in parallel. 19 // Start should return once it is ready to receive metrics. 20 // The passed in accumulator is the same as the one passed to Add(), so you 21 // can choose to save it in the plugin, or use the one received from Add(). 22 Start(acc Accumulator) error 23 24 // Add is called for each metric to be processed. The Add() function does not 25 // need to wait for the metric to be processed before returning, and it may 26 // be acceptable to let background goroutine(s) handle the processing if you 27 // have slow processing you need to do in parallel. 28 // Keep in mind Add() should not spawn unbounded goroutines, so you may need 29 // to use a semaphore or pool of workers (eg: reverse_dns plugin does this) 30 // Metrics you don't want to pass downstream should have metric.Drop() called, 31 // rather than simply omitting the acc.AddMetric() call 32 Add(metric Metric, acc Accumulator) error 33 34 // Stop gives you an opportunity to gracefully shut down the processor. 35 // Once Stop() is called, Add() will not be called any more. If you are using 36 // goroutines, you should wait for any in-progress metrics to be processed 37 // before returning from Stop(). 38 // When stop returns, you should no longer be writing metrics to the 39 // accumulator. 40 Stop() 41 }