2016-09-08 14:22:10 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2016-12-23 15:18:27 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins"
|
2016-09-08 14:22:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type RunningProcessor struct {
|
|
|
|
Name string
|
2016-12-23 15:18:27 +00:00
|
|
|
Processor plugins.Processor
|
2016-09-08 14:22:10 +00:00
|
|
|
Config *ProcessorConfig
|
|
|
|
}
|
|
|
|
|
2016-09-27 15:17:58 +00:00
|
|
|
type RunningProcessors []*RunningProcessor
|
|
|
|
|
|
|
|
func (rp RunningProcessors) Len() int { return len(rp) }
|
|
|
|
func (rp RunningProcessors) Swap(i, j int) { rp[i], rp[j] = rp[j], rp[i] }
|
|
|
|
func (rp RunningProcessors) Less(i, j int) bool { return rp[i].Config.Order < rp[j].Config.Order }
|
|
|
|
|
2016-09-08 14:22:10 +00:00
|
|
|
// FilterConfig containing a name and filter
|
|
|
|
type ProcessorConfig struct {
|
|
|
|
Name string
|
2016-09-27 15:17:58 +00:00
|
|
|
Order int64
|
2016-09-08 14:22:10 +00:00
|
|
|
Filter Filter
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:18:27 +00:00
|
|
|
func (rp *RunningProcessor) Apply(in ...plugins.Metric) []plugins.Metric {
|
|
|
|
ret := []plugins.Metric{}
|
2016-09-08 14:22:10 +00:00
|
|
|
|
|
|
|
for _, metric := range in {
|
|
|
|
if rp.Config.Filter.IsActive() {
|
|
|
|
// check if the filter should be applied to this metric
|
|
|
|
if ok := rp.Config.Filter.Apply(metric.Name(), metric.Fields(), metric.Tags()); !ok {
|
|
|
|
// this means filter should not be applied
|
|
|
|
ret = append(ret, metric)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This metric should pass through the filter, so call the filter Apply
|
|
|
|
// function and append results to the output slice.
|
|
|
|
ret = append(ret, rp.Processor.Apply(metric)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|