Tidy date processor
This commit is contained in:
parent
3e5cfad2b0
commit
a276ddfe97
|
@ -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
|
||||
2) bandwith capacity per month
|
||||
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
|
||||
```
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue