forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.go
42 lines (33 loc) · 872 Bytes
/
date.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
package date
import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/processors"
)
const sampleConfig = `
## New tag to create
tag_key = "month"
## Date format string, must be a representation of the Go "reference time"
## which is "Mon Jan 2 15:04:05 -0700 MST 2006".
date_format = "Jan"
`
type Date struct {
TagKey string `toml:"tag_key"`
DateFormat string `toml:"date_format"`
}
func (d *Date) SampleConfig() string {
return sampleConfig
}
func (d *Date) Description() string {
return "Dates measurements, tags, and fields that pass through this filter."
}
func (d *Date) Apply(in ...telegraf.Metric) []telegraf.Metric {
for _, point := range in {
point.AddTag(d.TagKey, point.Time().Format(d.DateFormat))
}
return in
}
func init() {
processors.Add("date", func() telegraf.Processor {
return &Date{}
})
}