You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm proposing a feature for processors.date. I needed grouping by time(1d,6h) (6 hours offset because of fact that shifts in factory starts at 6:00AM) and by new tag "month" - created by this plugin. All in factory counts between 6:00AM to 6:00AM.
Proposal:
I've made some changes in /plugins/processors/date/date.go. Now there is a new parameter in .conf file called time_shift with working as described in code section toml. Here is complete new code of date plugin:
package date
import (
"time"
"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"
## Time shift in hours. allows to configure tag value changing at diffierent time of day.
## Input as string. Working example: if time_shift = "-6.0h", month will change 6 hours later.
time_shift = "0.0h"
`
type Date struct {
TagKey string `toml:"tag_key"`
DateFormat string `toml:"date_format"`
TimeShift string `toml:"time_shift"`
}
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 {
timeshiftParsed, _ := time.ParseDuration(d.TimeShift)
timeref := point.Time().Add(timeshiftParsed)
point.AddTag(d.TagKey, timeref.Format(d.DateFormat))
}
return in
}
func init() {
processors.Add("date", func() telegraf.Processor {
return &Date{}
})
}
Current behavior:
In described case, when i group by tag month and time(1d,6h) at the last day of the month I get 2 values: for last month and new one which is a partial values of 6:00-6:00 work-day.
Desired behavior:
With new code adding a tag month is based on time+/-time_shift so I can group by month without having two values at the end of the month, everything works as I wanted.
Use case:
Maybe in other factories it will be useful too. Of course code implements various tag offsets in standard time format duration. In this case you would be able to make new fields with values grouping by work-days/months/days easily grouping by tag added with new offset parameter.
Feature Request
I'm proposing a feature for processors.date. I needed grouping by time(1d,6h) (6 hours offset because of fact that shifts in factory starts at 6:00AM) and by new tag "month" - created by this plugin. All in factory counts between 6:00AM to 6:00AM.
Proposal:
I've made some changes in /plugins/processors/date/date.go. Now there is a new parameter in .conf file called time_shift with working as described in code section toml. Here is complete new code of date plugin:
Current behavior:
In described case, when i group by tag month and time(1d,6h) at the last day of the month I get 2 values: for last month and new one which is a partial values of 6:00-6:00 work-day.
Desired behavior:
With new code adding a tag month is based on time+/-time_shift so I can group by month without having two values at the end of the month, everything works as I wanted.
Use case:
Maybe in other factories it will be useful too. Of course code implements various tag offsets in standard time format duration. In this case you would be able to make new fields with values grouping by work-days/months/days easily grouping by tag added with new offset parameter.
In attachment the new code:
date.go.txt
The text was updated successfully, but these errors were encountered: