telegraf/plugins/processors/clone/clone.go

53 lines
981 B
Go
Raw Normal View History

//go:generate ../../../tools/readme_config_includer/generator
2019-10-22 02:59:32 +08:00
package clone
import (
_ "embed"
2019-10-22 02:59:32 +08:00
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/processors"
)
//go:embed sample.conf
var sampleConfig string
2019-10-22 02:59:32 +08:00
type Clone struct {
NameOverride string
NamePrefix string
NameSuffix string
Tags map[string]string
}
func (*Clone) SampleConfig() string {
return sampleConfig
}
2019-10-22 02:59:32 +08:00
func (c *Clone) Apply(in ...telegraf.Metric) []telegraf.Metric {
out := make([]telegraf.Metric, 0, 2*len(in))
2019-10-22 02:59:32 +08:00
for _, original := range in {
m := original.Copy()
2019-10-22 02:59:32 +08:00
if len(c.NameOverride) > 0 {
m.SetName(c.NameOverride)
2019-10-22 02:59:32 +08:00
}
if len(c.NamePrefix) > 0 {
m.AddPrefix(c.NamePrefix)
2019-10-22 02:59:32 +08:00
}
if len(c.NameSuffix) > 0 {
m.AddSuffix(c.NameSuffix)
2019-10-22 02:59:32 +08:00
}
for key, value := range c.Tags {
m.AddTag(key, value)
2019-10-22 02:59:32 +08:00
}
out = append(out, m)
2019-10-22 02:59:32 +08:00
}
return append(out, in...)
2019-10-22 02:59:32 +08:00
}
func init() {
processors.Add("clone", func() telegraf.Processor {
return &Clone{}
})
}