2019-06-14 19:08:10 +00:00
|
|
|
package date
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/influxdata/telegraf"
|
|
|
|
"github.com/influxdata/telegraf/plugins/processors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const sampleConfig = `
|
2019-06-14 19:26:47 +00:00
|
|
|
## New tag to create
|
|
|
|
tag_key = "month"
|
2019-06-14 19:08:10 +00:00
|
|
|
|
2019-06-14 19:26:47 +00:00
|
|
|
## 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"
|
2019-06-14 19:08:10 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type Date struct {
|
2019-06-14 19:26:47 +00:00
|
|
|
TagKey string `toml:"tag_key"`
|
|
|
|
DateFormat string `toml:"date_format"`
|
2019-06-14 19:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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{}
|
|
|
|
})
|
|
|
|
}
|