Exemplo n.º 1
0
// gatherer runs the inputs that have been configured with their own
// reporting interval.
func (a *Agent) gatherer(
	shutdown chan struct{},
	input *models.RunningInput,
	interval time.Duration,
	metricC chan telegraf.Metric,
) {
	defer panicRecover(input)

	ticker := time.NewTicker(interval)
	defer ticker.Stop()

	for {
		acc := NewAccumulator(input, metricC)
		acc.SetPrecision(a.Config.Agent.Precision.Duration,
			a.Config.Agent.Interval.Duration)
		input.SetDebug(a.Config.Agent.Debug)
		input.SetDefaultTags(a.Config.Tags)

		internal.RandomSleep(a.Config.Agent.CollectionJitter.Duration, shutdown)

		start := time.Now()
		gatherWithTimeout(shutdown, input, acc, interval)
		elapsed := time.Since(start)

		log.Printf("D! Input [%s] gathered metrics, (%s interval) in %s\n",
			input.Name(), interval, elapsed)

		select {
		case <-shutdown:
			return
		case <-ticker.C:
			continue
		}
	}
}