From a276ddfe976861ab6b00d0af56a0d77fa28daf31 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 14 Jun 2019 12:26:47 -0700 Subject: [PATCH] Tidy date processor --- plugins/processors/date/README.md | 34 ++++++++++++------------- plugins/processors/date/date.go | 41 ++++++------------------------- 2 files changed, 23 insertions(+), 52 deletions(-) diff --git a/plugins/processors/date/README.md b/plugins/processors/date/README.md index e2bd245e5..1a68119e1 100644 --- a/plugins/processors/date/README.md +++ b/plugins/processors/date/README.md @@ -1,31 +1,29 @@ # Date Processor Plugin -The `date` processor adds the months and years as tags to your data. +Use the `date` processor to add the metric timestamp as a human readable tag. -Provides the ability to group by months or years. +A common use is to add a tag that can be used to group by month or year. -A few example usecases include: -1) consumption data for utilities on per month basis +A few example usecases include: +1) consumption data for utilities on per month basis 2) bandwith capacity per month -3) compare energy production or sales on a yearly or monthly basis +3) compare energy production or sales on a yearly or monthly basis - -### Configuration: +### Configuration ```toml [[processors.date]] - ##Specify the date tags to add rename operation. - tagKey = "month" - dateFormat = "Jan" + ## 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" ``` -### Tags: - -Tags are applied by this processor. - -### Example processing: +### Example -``` -- throughput, hostname=example.com lower=10i,upper=1000i,mean=500i 1502489900000000000 -+ throughput,host=backend.example.com,month=Mar min=10i,max=1000i,mean=500i 1502489900000000000 +```diff +- throughput lower=10i,upper=1000i,mean=500i 1560540094000000000 ++ throughput,month=Jun lower=10i,upper=1000i,mean=500i 1560540094000000000 ``` diff --git a/plugins/processors/date/date.go b/plugins/processors/date/date.go index 844f99cc7..479106ef2 100644 --- a/plugins/processors/date/date.go +++ b/plugins/processors/date/date.go @@ -6,15 +6,17 @@ import ( ) const sampleConfig = ` -##Specify the date tags to add -tagKey = "month" -dateFormat = "%m" + ## 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:"tagKey"` - DateFormat string `toml:"dateFormat"` + TagKey string `toml:"tag_key"` + DateFormat string `toml:"date_format"` } func (d *Date) SampleConfig() string { @@ -28,11 +30,9 @@ func (d *Date) Description() string { 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() { @@ -40,30 +40,3 @@ func init() { return &Date{} }) } - -/** - * - -[processors.date] - jdfj - - ##Set Months to True or False - tagKey = "month" - dateFormat = "%m" // January - -[processors.date] - jdfj - - ##Set Months to True or False - tagKey = "day_of_week" - dateFormat = "%d" // Wednesday - - - # [[processors.regex.fields]] - # key = "request" - # pattern = ".*category=(\\w+).*" - # replacement = "${1}" - # result_key = "search_category" - - -*/