2022-05-25 22:59:41 +08:00
|
|
|
//go:generate ../../../tools/readme_config_includer/generator
|
2019-10-22 02:59:32 +08:00
|
|
|
package clone
|
|
|
|
|
|
|
|
|
|
import (
|
2022-05-25 22:59:41 +08:00
|
|
|
_ "embed"
|
|
|
|
|
|
2019-10-22 02:59:32 +08:00
|
|
|
"github.com/influxdata/telegraf"
|
|
|
|
|
"github.com/influxdata/telegraf/plugins/processors"
|
|
|
|
|
)
|
|
|
|
|
|
2022-05-25 22:59:41 +08:00
|
|
|
//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
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 22:59:41 +08:00
|
|
|
func (*Clone) SampleConfig() string {
|
|
|
|
|
return sampleConfig
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 02:59:32 +08:00
|
|
|
func (c *Clone) Apply(in ...telegraf.Metric) []telegraf.Metric {
|
|
|
|
|
cloned := []telegraf.Metric{}
|
|
|
|
|
|
|
|
|
|
for _, metric := range in {
|
|
|
|
|
cloned = append(cloned, metric.Copy())
|
|
|
|
|
|
|
|
|
|
if len(c.NameOverride) > 0 {
|
|
|
|
|
metric.SetName(c.NameOverride)
|
|
|
|
|
}
|
|
|
|
|
if len(c.NamePrefix) > 0 {
|
|
|
|
|
metric.AddPrefix(c.NamePrefix)
|
|
|
|
|
}
|
|
|
|
|
if len(c.NameSuffix) > 0 {
|
|
|
|
|
metric.AddSuffix(c.NameSuffix)
|
|
|
|
|
}
|
|
|
|
|
for key, value := range c.Tags {
|
|
|
|
|
metric.AddTag(key, value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return append(in, cloned...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
processors.Add("clone", func() telegraf.Processor {
|
|
|
|
|
return &Clone{}
|
|
|
|
|
})
|
|
|
|
|
}
|