forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone.go
60 lines (50 loc) · 1.23 KB
/
clone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package clone
import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/processors"
)
var sampleConfig = `
## All modifications on inputs and aggregators can be overridden:
# name_override = "new_name"
# name_prefix = "new_name_prefix"
# name_suffix = "new_name_suffix"
## Tags to be added (all values must be strings)
# [processors.clone.tags]
# additional_tag = "tag_value"
`
type Clone struct {
NameOverride string
NamePrefix string
NameSuffix string
Tags map[string]string
}
func (c *Clone) SampleConfig() string {
return sampleConfig
}
func (c *Clone) Description() string {
return "Clone metrics and apply modifications."
}
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{}
})
}