-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Histogram support aggregation #1364
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,28 +242,43 @@ func (a *Agent) flush() { | |
} | ||
}(o) | ||
} | ||
|
||
wg.Wait() | ||
} | ||
|
||
// flusher monitors the metrics input channel and flushes on the minimum interval | ||
func (a *Agent) flusher(shutdown chan struct{}, metricC chan telegraf.Metric) error { | ||
var metricStream chan telegraf.Metric | ||
stopFilter := make(chan struct{}, len(a.Config.Filters)) | ||
// Inelegant, but this sleep is to allow the Gather threads to run, so that | ||
// the flusher will flush after metrics are collected. | ||
time.Sleep(time.Millisecond * 200) | ||
|
||
ticker := time.NewTicker(a.Config.Agent.FlushInterval.Duration) | ||
metricStream = metricC | ||
if len(a.Config.Filters) != 0 { | ||
for _, name := range a.Config.FiltersOrder { | ||
filter := a.Config.Filters[name] | ||
log.Printf("Filter %s is enabled", name) | ||
metricStream = filter.Pipe(metricStream) | ||
go func(f telegraf.Filter) { | ||
f.Start(stopFilter) | ||
}(filter) | ||
} | ||
} | ||
|
||
for { | ||
select { | ||
case <-shutdown: | ||
//sending shutdown signal for all filters | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't filters just use the shutdown signal directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can do that but I had problem with carrying the stop signal since the last receiver should not send the signal again or it will block for ever make it hard to shutdown telegraf process (clean shutdown) |
||
for range a.Config.Filters { | ||
stopFilter <- struct{}{} | ||
} | ||
log.Println("Hang on, flushing any cached metrics before shutdown") | ||
a.flush() | ||
return nil | ||
case <-ticker.C: | ||
internal.RandomSleep(a.Config.Agent.FlushJitter.Duration, shutdown) | ||
a.flush() | ||
case m := <-metricC: | ||
case m := <-metricStream: | ||
for _, o := range a.Config.Outputs { | ||
o.AddMetric(m) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package telegraf | ||
|
||
type Filter interface { | ||
// SampleConfig returns the default configuration of the Input | ||
SampleConfig() string | ||
|
||
// Description returns a one-sentence description on the Input | ||
Description() string | ||
|
||
//create pipe for filter | ||
Pipe(in chan Metric) chan Metric | ||
|
||
// start the filter | ||
Start(shutdown chan struct{}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package all | ||
|
||
import ( | ||
_ "github.com/influxdata/telegraf/plugins/filters/histogram" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this in a goroutine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter suppose to work in is own context like other plugins it may have timer inside and i don't want to block the agent code from collecting metrics or flushing them. consider filter as pipe with input and output (black box). Histogram filter for example has timer for flushing metrics on specific intervals