2016-01-27 21:21:36 +00:00
|
|
|
package agent
|
2015-04-01 16:34:32 +00:00
|
|
|
|
|
|
|
import (
|
2015-05-18 21:10:12 +00:00
|
|
|
"fmt"
|
2015-04-01 16:34:32 +00:00
|
|
|
"log"
|
2015-04-07 16:56:40 +00:00
|
|
|
"os"
|
2016-01-26 08:19:34 +00:00
|
|
|
"runtime"
|
2015-05-20 05:19:32 +00:00
|
|
|
"sync"
|
2015-04-07 16:23:35 +00:00
|
|
|
"time"
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2016-01-27 21:21:36 +00:00
|
|
|
"github.com/influxdata/telegraf"
|
2016-05-30 22:24:42 +00:00
|
|
|
"github.com/influxdata/telegraf/internal"
|
2016-01-20 18:57:35 +00:00
|
|
|
"github.com/influxdata/telegraf/internal/config"
|
2016-01-22 18:54:12 +00:00
|
|
|
"github.com/influxdata/telegraf/internal/models"
|
2016-11-07 08:34:46 +00:00
|
|
|
"github.com/influxdata/telegraf/selfstat"
|
2015-04-01 16:34:32 +00:00
|
|
|
)
|
|
|
|
|
2015-08-04 14:58:32 +00:00
|
|
|
// Agent runs telegraf and collects data based on the given config
|
2015-04-01 16:34:32 +00:00
|
|
|
type Agent struct {
|
2015-11-24 21:22:11 +00:00
|
|
|
Config *config.Config
|
2015-04-01 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 14:58:32 +00:00
|
|
|
// NewAgent returns an Agent struct based off the given Config
|
2015-11-24 21:22:11 +00:00
|
|
|
func NewAgent(config *config.Config) (*Agent, error) {
|
2015-11-26 01:42:07 +00:00
|
|
|
a := &Agent{
|
|
|
|
Config: config,
|
2015-09-02 16:30:44 +00:00
|
|
|
}
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2016-03-21 21:33:19 +00:00
|
|
|
if !a.Config.Agent.OmitHostname {
|
|
|
|
if a.Config.Agent.Hostname == "" {
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
a.Config.Agent.Hostname = hostname
|
2015-04-07 16:56:40 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 21:33:19 +00:00
|
|
|
config.Tags["host"] = a.Config.Agent.Hostname
|
2015-11-24 01:00:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 01:42:07 +00:00
|
|
|
return a, nil
|
2015-04-07 00:24:24 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 17:04:25 +00:00
|
|
|
// Connect connects to all configured outputs
|
2015-08-04 14:58:32 +00:00
|
|
|
func (a *Agent) Connect() error {
|
2015-11-24 21:22:11 +00:00
|
|
|
for _, o := range a.Config.Outputs {
|
|
|
|
switch ot := o.Output.(type) {
|
2016-01-27 21:21:36 +00:00
|
|
|
case telegraf.ServiceOutput:
|
2015-10-22 16:17:57 +00:00
|
|
|
if err := ot.Start(); err != nil {
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("E! Service for output %s failed to start, exiting\n%s\n",
|
2015-11-24 21:22:11 +00:00
|
|
|
o.Name, err.Error())
|
2015-10-22 16:17:57 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("D! Attempting connection to output: %s\n", o.Name)
|
2015-11-24 21:22:11 +00:00
|
|
|
err := o.Output.Connect()
|
2015-08-07 20:31:25 +00:00
|
|
|
if err != nil {
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("E! Failed to connect to output %s, retrying in 15s, "+
|
2016-02-16 00:21:38 +00:00
|
|
|
"error was '%s' \n", o.Name, err)
|
2015-09-19 01:02:16 +00:00
|
|
|
time.Sleep(15 * time.Second)
|
2015-11-24 21:22:11 +00:00
|
|
|
err = o.Output.Connect()
|
2015-09-19 01:02:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-08-07 20:31:25 +00:00
|
|
|
}
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("D! Successfully connected to output: %s\n", o.Name)
|
2015-04-01 16:34:32 +00:00
|
|
|
}
|
2015-08-07 20:31:25 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-08-12 17:04:25 +00:00
|
|
|
// Close closes the connection to all configured outputs
|
|
|
|
func (a *Agent) Close() error {
|
|
|
|
var err error
|
2015-11-24 21:22:11 +00:00
|
|
|
for _, o := range a.Config.Outputs {
|
|
|
|
err = o.Output.Close()
|
|
|
|
switch ot := o.Output.(type) {
|
2016-01-27 21:21:36 +00:00
|
|
|
case telegraf.ServiceOutput:
|
2015-10-22 16:17:57 +00:00
|
|
|
ot.Stop()
|
|
|
|
}
|
2015-08-12 17:04:25 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-28 11:31:11 +00:00
|
|
|
func panicRecover(input *models.RunningInput) {
|
2016-01-26 08:19:34 +00:00
|
|
|
if err := recover(); err != nil {
|
|
|
|
trace := make([]byte, 2048)
|
|
|
|
runtime.Stack(trace, true)
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("E! FATAL: Input [%s] panicked: %s, Stack:\n%s\n",
|
2016-09-08 14:22:10 +00:00
|
|
|
input.Name(), err, trace)
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Println("E! PLEASE REPORT THIS PANIC ON GITHUB with " +
|
2016-01-26 08:19:34 +00:00
|
|
|
"stack trace, configuration, and OS information: " +
|
|
|
|
"https://github.com/influxdata/telegraf/issues/new")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 15:36:58 +00:00
|
|
|
// gatherer runs the inputs that have been configured with their own
|
2015-08-26 17:02:10 +00:00
|
|
|
// reporting interval.
|
2016-05-19 15:36:58 +00:00
|
|
|
func (a *Agent) gatherer(
|
2015-10-16 22:13:32 +00:00
|
|
|
shutdown chan struct{},
|
2016-07-28 11:31:11 +00:00
|
|
|
input *models.RunningInput,
|
2016-05-19 15:36:58 +00:00
|
|
|
interval time.Duration,
|
2016-01-27 23:15:14 +00:00
|
|
|
metricC chan telegraf.Metric,
|
2016-09-08 14:22:10 +00:00
|
|
|
) {
|
2016-01-26 08:19:34 +00:00
|
|
|
defer panicRecover(input)
|
|
|
|
|
2016-11-07 08:34:46 +00:00
|
|
|
GatherTime := selfstat.RegisterTiming("gather",
|
|
|
|
"gather_time_ns",
|
|
|
|
map[string]string{"input": input.Config.Name},
|
|
|
|
)
|
|
|
|
|
|
|
|
acc := NewAccumulator(input, metricC)
|
|
|
|
acc.SetPrecision(a.Config.Agent.Precision.Duration,
|
|
|
|
a.Config.Agent.Interval.Duration)
|
|
|
|
|
2016-05-19 15:36:58 +00:00
|
|
|
ticker := time.NewTicker(interval)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
2015-05-20 05:19:32 +00:00
|
|
|
for {
|
2016-05-30 22:24:42 +00:00
|
|
|
internal.RandomSleep(a.Config.Agent.CollectionJitter.Duration, shutdown)
|
2015-05-20 05:19:32 +00:00
|
|
|
|
2016-05-30 22:24:42 +00:00
|
|
|
start := time.Now()
|
2016-05-19 15:36:58 +00:00
|
|
|
gatherWithTimeout(shutdown, input, acc, interval)
|
2015-09-28 20:08:28 +00:00
|
|
|
elapsed := time.Since(start)
|
2015-08-26 23:43:09 +00:00
|
|
|
|
2016-11-07 08:34:46 +00:00
|
|
|
GatherTime.Incr(elapsed.Nanoseconds())
|
2015-05-20 05:19:32 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-shutdown:
|
2016-09-08 14:22:10 +00:00
|
|
|
return
|
2015-05-20 05:19:32 +00:00
|
|
|
case <-ticker.C:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 15:36:58 +00:00
|
|
|
// gatherWithTimeout gathers from the given input, with the given timeout.
|
|
|
|
// when the given timeout is reached, gatherWithTimeout logs an error message
|
|
|
|
// but continues waiting for it to return. This is to avoid leaving behind
|
|
|
|
// hung processes, and to prevent re-calling the same hung process over and
|
|
|
|
// over.
|
|
|
|
func gatherWithTimeout(
|
|
|
|
shutdown chan struct{},
|
2016-07-28 11:31:11 +00:00
|
|
|
input *models.RunningInput,
|
2016-05-19 15:36:58 +00:00
|
|
|
acc *accumulator,
|
|
|
|
timeout time.Duration,
|
|
|
|
) {
|
|
|
|
ticker := time.NewTicker(timeout)
|
|
|
|
defer ticker.Stop()
|
|
|
|
done := make(chan error)
|
|
|
|
go func() {
|
|
|
|
done <- input.Input.Gather(acc)
|
|
|
|
}()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case err := <-done:
|
|
|
|
if err != nil {
|
2017-01-29 22:28:52 +00:00
|
|
|
acc.AddError(err)
|
2016-05-19 15:36:58 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
case <-ticker.C:
|
2017-01-29 22:28:52 +00:00
|
|
|
err := fmt.Errorf("took longer to collect than collection interval (%s)",
|
|
|
|
timeout)
|
|
|
|
acc.AddError(err)
|
2016-05-19 15:36:58 +00:00
|
|
|
continue
|
|
|
|
case <-shutdown:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
// Test verifies that we can 'Gather' from all inputs with their configured
|
2015-08-04 14:58:32 +00:00
|
|
|
// Config struct
|
2015-04-07 00:24:24 +00:00
|
|
|
func (a *Agent) Test() error {
|
2015-10-16 22:13:32 +00:00
|
|
|
shutdown := make(chan struct{})
|
|
|
|
defer close(shutdown)
|
2016-01-27 23:15:14 +00:00
|
|
|
metricC := make(chan telegraf.Metric)
|
2015-04-07 00:24:24 +00:00
|
|
|
|
2015-10-22 00:32:43 +00:00
|
|
|
// dummy receiver for the point channel
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
2016-01-27 23:15:14 +00:00
|
|
|
case <-metricC:
|
2015-10-22 00:32:43 +00:00
|
|
|
// do nothing
|
|
|
|
case <-shutdown:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2015-04-07 00:24:24 +00:00
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
for _, input := range a.Config.Inputs {
|
2016-09-08 14:22:10 +00:00
|
|
|
acc := NewAccumulator(input, metricC)
|
2016-06-13 14:21:11 +00:00
|
|
|
acc.SetPrecision(a.Config.Agent.Precision.Duration,
|
|
|
|
a.Config.Agent.Interval.Duration)
|
2016-09-08 14:22:10 +00:00
|
|
|
input.SetTrace(true)
|
|
|
|
input.SetDefaultTags(a.Config.Tags)
|
2015-05-20 05:19:32 +00:00
|
|
|
|
2016-09-08 14:22:10 +00:00
|
|
|
fmt.Printf("* Plugin: %s, Collection 1\n", input.Name())
|
2016-01-07 20:39:43 +00:00
|
|
|
if input.Config.Interval != 0 {
|
|
|
|
fmt.Printf("* Internal: %s\n", input.Config.Interval)
|
2015-05-20 05:19:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
if err := input.Input.Gather(acc); err != nil {
|
2015-04-07 00:24:24 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-09-21 17:05:58 +00:00
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
// Special instructions for some inputs. cpu, for example, needs to be
|
2015-09-23 20:54:22 +00:00
|
|
|
// run twice in order to return cpu usage percentages.
|
2016-09-08 14:22:10 +00:00
|
|
|
switch input.Name() {
|
2016-01-20 00:28:02 +00:00
|
|
|
case "cpu", "mongodb", "procstat":
|
2015-09-23 20:54:22 +00:00
|
|
|
time.Sleep(500 * time.Millisecond)
|
2016-09-08 14:22:10 +00:00
|
|
|
fmt.Printf("* Plugin: %s, Collection 2\n", input.Name())
|
2016-01-07 20:39:43 +00:00
|
|
|
if err := input.Input.Gather(acc); err != nil {
|
2015-09-23 20:54:22 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-09-21 17:05:58 +00:00
|
|
|
}
|
2015-04-07 00:24:24 +00:00
|
|
|
|
2015-09-23 20:54:22 +00:00
|
|
|
}
|
2015-04-07 00:24:24 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-16 00:21:38 +00:00
|
|
|
// flush writes a list of metrics to all configured outputs
|
2016-01-22 18:54:12 +00:00
|
|
|
func (a *Agent) flush() {
|
2015-10-21 20:05:27 +00:00
|
|
|
var wg sync.WaitGroup
|
2016-01-22 18:54:12 +00:00
|
|
|
|
|
|
|
wg.Add(len(a.Config.Outputs))
|
2015-11-24 21:22:11 +00:00
|
|
|
for _, o := range a.Config.Outputs {
|
2016-07-28 11:31:11 +00:00
|
|
|
go func(output *models.RunningOutput) {
|
2016-01-22 18:54:12 +00:00
|
|
|
defer wg.Done()
|
|
|
|
err := output.Write()
|
|
|
|
if err != nil {
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("E! Error writing to output [%s]: %s\n",
|
2016-01-22 18:54:12 +00:00
|
|
|
output.Name, err.Error())
|
|
|
|
}
|
|
|
|
}(o)
|
2015-10-21 16:57:51 +00:00
|
|
|
}
|
2016-01-22 18:54:12 +00:00
|
|
|
|
|
|
|
wg.Wait()
|
2015-10-16 22:13:32 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 00:21:38 +00:00
|
|
|
// flusher monitors the metrics input channel and flushes on the minimum interval
|
2016-01-27 23:15:14 +00:00
|
|
|
func (a *Agent) flusher(shutdown chan struct{}, metricC chan telegraf.Metric) error {
|
2015-10-20 22:45:31 +00:00
|
|
|
// Inelegant, but this sleep is to allow the Gather threads to run, so that
|
|
|
|
// the flusher will flush after metrics are collected.
|
2016-09-08 14:22:10 +00:00
|
|
|
time.Sleep(time.Millisecond * 300)
|
2015-10-23 17:23:08 +00:00
|
|
|
|
2016-09-08 14:22:10 +00:00
|
|
|
// create an output metric channel and a gorouting that continously passes
|
|
|
|
// each metric onto the output plugins & aggregators.
|
|
|
|
outMetricC := make(chan telegraf.Metric, 100)
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-shutdown:
|
|
|
|
if len(outMetricC) > 0 {
|
|
|
|
// keep going until outMetricC is flushed
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return
|
|
|
|
case m := <-outMetricC:
|
|
|
|
// if dropOriginal is set to true, then we will only send this
|
|
|
|
// metric to the aggregators, not the outputs.
|
|
|
|
var dropOriginal bool
|
|
|
|
if !m.IsAggregate() {
|
|
|
|
for _, agg := range a.Config.Aggregators {
|
2016-11-23 12:30:31 +00:00
|
|
|
if ok := agg.Add(m.Copy()); ok {
|
2016-09-08 14:22:10 +00:00
|
|
|
dropOriginal = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !dropOriginal {
|
|
|
|
for i, o := range a.Config.Outputs {
|
|
|
|
if i == len(a.Config.Outputs)-1 {
|
|
|
|
o.AddMetric(m)
|
|
|
|
} else {
|
2016-11-23 12:30:31 +00:00
|
|
|
o.AddMetric(m.Copy())
|
2016-09-08 14:22:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2015-10-23 17:23:08 +00:00
|
|
|
|
2016-09-08 14:22:10 +00:00
|
|
|
ticker := time.NewTicker(a.Config.Agent.FlushInterval.Duration)
|
2017-01-17 23:01:12 +00:00
|
|
|
semaphore := make(chan struct{}, 1)
|
2015-10-16 22:13:32 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-shutdown:
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Println("I! Hang on, flushing any cached metrics before shutdown")
|
2016-09-08 14:22:10 +00:00
|
|
|
// wait for outMetricC to get flushed before flushing outputs
|
|
|
|
wg.Wait()
|
2016-01-22 18:54:12 +00:00
|
|
|
a.flush()
|
2015-10-16 22:13:32 +00:00
|
|
|
return nil
|
|
|
|
case <-ticker.C:
|
2017-01-17 23:01:12 +00:00
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case semaphore <- struct{}{}:
|
|
|
|
internal.RandomSleep(a.Config.Agent.FlushJitter.Duration, shutdown)
|
|
|
|
a.flush()
|
|
|
|
<-semaphore
|
|
|
|
default:
|
|
|
|
// skipping this flush because one is already happening
|
|
|
|
log.Println("W! Skipping a scheduled flush because there is" +
|
|
|
|
" already a flush ongoing.")
|
|
|
|
}
|
|
|
|
}()
|
2016-09-08 14:22:10 +00:00
|
|
|
case metric := <-metricC:
|
2016-10-07 15:43:44 +00:00
|
|
|
// NOTE potential bottleneck here as we put each metric through the
|
|
|
|
// processors serially.
|
2016-09-08 14:22:10 +00:00
|
|
|
mS := []telegraf.Metric{metric}
|
|
|
|
for _, processor := range a.Config.Processors {
|
|
|
|
mS = processor.Apply(mS...)
|
2016-10-03 17:49:30 +00:00
|
|
|
}
|
2016-09-08 14:22:10 +00:00
|
|
|
for _, m := range mS {
|
|
|
|
outMetricC <- m
|
2016-01-22 18:54:12 +00:00
|
|
|
}
|
2015-10-16 22:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:58:32 +00:00
|
|
|
// Run runs the agent daemon, gathering every Interval
|
2015-04-07 16:23:58 +00:00
|
|
|
func (a *Agent) Run(shutdown chan struct{}) error {
|
2015-05-20 05:19:32 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("I! Agent Config: Interval:%s, Quiet:%#v, Hostname:%#v, "+
|
2016-01-15 19:25:56 +00:00
|
|
|
"Flush Interval:%s \n",
|
2016-09-30 21:37:56 +00:00
|
|
|
a.Config.Agent.Interval.Duration, a.Config.Agent.Quiet,
|
2016-01-07 20:39:43 +00:00
|
|
|
a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration)
|
2015-10-23 17:23:08 +00:00
|
|
|
|
2016-02-16 00:21:38 +00:00
|
|
|
// channel shared between all input threads for accumulating metrics
|
2016-10-07 15:43:44 +00:00
|
|
|
metricC := make(chan telegraf.Metric, 100)
|
2015-10-16 22:13:32 +00:00
|
|
|
|
2016-09-08 14:22:10 +00:00
|
|
|
// Start all ServicePlugins
|
2016-02-17 21:50:19 +00:00
|
|
|
for _, input := range a.Config.Inputs {
|
2016-11-07 08:34:46 +00:00
|
|
|
input.SetDefaultTags(a.Config.Tags)
|
2016-02-17 21:50:19 +00:00
|
|
|
switch p := input.Input.(type) {
|
|
|
|
case telegraf.ServiceInput:
|
2016-09-08 14:22:10 +00:00
|
|
|
acc := NewAccumulator(input, metricC)
|
2016-06-13 14:21:11 +00:00
|
|
|
// Service input plugins should set their own precision of their
|
|
|
|
// metrics.
|
2016-09-08 14:22:10 +00:00
|
|
|
acc.SetPrecision(time.Nanosecond, 0)
|
2016-02-17 21:50:19 +00:00
|
|
|
if err := p.Start(acc); err != nil {
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("E! Service for input %s failed to start, exiting\n%s\n",
|
2016-09-08 14:22:10 +00:00
|
|
|
input.Name(), err.Error())
|
2016-02-17 21:50:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer p.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 20:05:27 +00:00
|
|
|
// Round collection to nearest interval by sleeping
|
2015-11-26 01:42:07 +00:00
|
|
|
if a.Config.Agent.RoundInterval {
|
|
|
|
i := int64(a.Config.Agent.Interval.Duration)
|
2015-10-21 20:05:27 +00:00
|
|
|
time.Sleep(time.Duration(i - (time.Now().UnixNano() % i)))
|
|
|
|
}
|
|
|
|
|
2015-10-16 22:13:32 +00:00
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2016-01-27 23:15:14 +00:00
|
|
|
if err := a.flusher(shutdown, metricC); err != nil {
|
2016-09-30 21:37:56 +00:00
|
|
|
log.Printf("E! Flusher routine failed, exiting: %s\n", err.Error())
|
2015-10-16 22:13:32 +00:00
|
|
|
close(shutdown)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-10-10 12:43:47 +00:00
|
|
|
wg.Add(len(a.Config.Aggregators))
|
|
|
|
for _, aggregator := range a.Config.Aggregators {
|
|
|
|
go func(agg *models.RunningAggregator) {
|
|
|
|
defer wg.Done()
|
|
|
|
acc := NewAccumulator(agg, metricC)
|
|
|
|
acc.SetPrecision(a.Config.Agent.Precision.Duration,
|
|
|
|
a.Config.Agent.Interval.Duration)
|
|
|
|
agg.Run(acc, shutdown)
|
|
|
|
}(aggregator)
|
|
|
|
}
|
|
|
|
|
2016-05-19 15:36:58 +00:00
|
|
|
wg.Add(len(a.Config.Inputs))
|
2016-01-07 20:39:43 +00:00
|
|
|
for _, input := range a.Config.Inputs {
|
2016-05-19 15:36:58 +00:00
|
|
|
interval := a.Config.Agent.Interval.Duration
|
|
|
|
// overwrite global interval if this plugin has it's own.
|
2016-01-07 20:39:43 +00:00
|
|
|
if input.Config.Interval != 0 {
|
2016-05-19 15:36:58 +00:00
|
|
|
interval = input.Config.Interval
|
2015-05-20 05:19:32 +00:00
|
|
|
}
|
2016-07-28 11:31:11 +00:00
|
|
|
go func(in *models.RunningInput, interv time.Duration) {
|
2016-05-19 15:36:58 +00:00
|
|
|
defer wg.Done()
|
2016-10-03 17:49:30 +00:00
|
|
|
a.gatherer(shutdown, in, interv, metricC)
|
2016-05-19 15:36:58 +00:00
|
|
|
}(input, interval)
|
2015-05-20 05:19:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 15:36:58 +00:00
|
|
|
wg.Wait()
|
|
|
|
return nil
|
2015-04-01 16:34:32 +00:00
|
|
|
}
|