Tidy date processor

This commit is contained in:
Daniel Nelson 2019-06-14 12:26:47 -07:00
parent 3e5cfad2b0
commit a276ddfe97
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
2 changed files with 23 additions and 52 deletions

View File

@ -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
```

View File

@ -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"
*/