forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
override.go
56 lines (48 loc) · 1.18 KB
/
override.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
package override
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.override.tags]
# additional_tag = "tag_value"
`
type Override struct {
NameOverride string
NamePrefix string
NameSuffix string
Tags map[string]string
}
func (p *Override) SampleConfig() string {
return sampleConfig
}
func (p *Override) Description() string {
return "Apply metric modifications using override semantics."
}
func (p *Override) Apply(in ...telegraf.Metric) []telegraf.Metric {
for _, metric := range in {
if len(p.NameOverride) > 0 {
metric.SetName(p.NameOverride)
}
if len(p.NamePrefix) > 0 {
metric.AddPrefix(p.NamePrefix)
}
if len(p.NameSuffix) > 0 {
metric.AddSuffix(p.NameSuffix)
}
for key, value := range p.Tags {
metric.AddTag(key, value)
}
}
return in
}
func init() {
processors.Add("override", func() telegraf.Processor {
return &Override{}
})
}