2016-01-27 21:21:36 +00:00
|
|
|
package agent
|
2015-04-01 16:34:32 +00:00
|
|
|
|
|
|
|
import (
|
2016-01-19 20:00:36 +00:00
|
|
|
cryptorand "crypto/rand"
|
2015-05-18 21:10:12 +00:00
|
|
|
"fmt"
|
2015-04-01 16:34:32 +00:00
|
|
|
"log"
|
2015-10-23 17:23:08 +00:00
|
|
|
"math/big"
|
2016-01-19 20:00:36 +00:00
|
|
|
"math/rand"
|
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-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-05-25 17:38:25 +00:00
|
|
|
"github.com/influxdata/telegraf/internal/webserver"
|
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 {
|
2016-02-22 18:40:27 +00:00
|
|
|
o.Quiet = a.Config.Agent.Quiet
|
|
|
|
|
2015-11-24 21:22:11 +00:00
|
|
|
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 {
|
|
|
|
log.Printf("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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 01:42:07 +00:00
|
|
|
if a.Config.Agent.Debug {
|
2015-11-24 21:22:11 +00:00
|
|
|
log.Printf("Attempting connection to output: %s\n", o.Name)
|
2015-09-09 21:56:10 +00:00
|
|
|
}
|
2015-11-24 21:22:11 +00:00
|
|
|
err := o.Output.Connect()
|
2015-08-07 20:31:25 +00:00
|
|
|
if err != nil {
|
2016-02-16 00:21:38 +00:00
|
|
|
log.Printf("Failed to connect to output %s, retrying in 15s, "+
|
|
|
|
"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
|
|
|
}
|
2015-11-26 01:42:07 +00:00
|
|
|
if a.Config.Agent.Debug {
|
2015-11-24 21:22:11 +00:00
|
|
|
log.Printf("Successfully connected to output: %s\n", o.Name)
|
2015-08-26 17:02:10 +00:00
|
|
|
}
|
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-01-27 21:21:36 +00:00
|
|
|
func panicRecover(input *internal_models.RunningInput) {
|
2016-01-26 08:19:34 +00:00
|
|
|
if err := recover(); err != nil {
|
|
|
|
trace := make([]byte, 2048)
|
|
|
|
runtime.Stack(trace, true)
|
|
|
|
log.Printf("FATAL: Input [%s] panicked: %s, Stack:\n%s\n",
|
|
|
|
input.Name, err, trace)
|
|
|
|
log.Println("PLEASE REPORT THIS PANIC ON GITHUB with " +
|
|
|
|
"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-01-27 21:21:36 +00:00
|
|
|
input *internal_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,
|
2015-10-16 22:13:32 +00:00
|
|
|
) error {
|
2016-01-26 08:19:34 +00:00
|
|
|
defer panicRecover(input)
|
|
|
|
|
2016-05-19 15:36:58 +00:00
|
|
|
ticker := time.NewTicker(interval)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
jitter := a.Config.Agent.CollectionJitter.Duration.Nanoseconds()
|
2015-05-20 05:19:32 +00:00
|
|
|
|
|
|
|
for {
|
2015-08-26 23:43:09 +00:00
|
|
|
var outerr error
|
2015-09-28 20:08:28 +00:00
|
|
|
start := time.Now()
|
2015-05-20 05:19:32 +00:00
|
|
|
|
2016-01-27 23:15:14 +00:00
|
|
|
acc := NewAccumulator(input.Config, metricC)
|
2015-11-26 01:42:07 +00:00
|
|
|
acc.SetDebug(a.Config.Agent.Debug)
|
2016-01-27 21:21:36 +00:00
|
|
|
acc.setDefaultTags(a.Config.Tags)
|
2015-08-26 23:43:09 +00:00
|
|
|
|
2016-05-19 15:36:58 +00:00
|
|
|
if jitter != 0 {
|
|
|
|
nanoSleep := rand.Int63n(jitter)
|
|
|
|
d, err := time.ParseDuration(fmt.Sprintf("%dns", nanoSleep))
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Jittering collection interval failed for plugin %s",
|
|
|
|
input.Name)
|
|
|
|
} else {
|
|
|
|
time.Sleep(d)
|
|
|
|
}
|
2015-09-02 16:30:44 +00:00
|
|
|
}
|
2015-05-20 05:19:32 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
if outerr != nil {
|
|
|
|
return outerr
|
2015-08-07 20:31:25 +00:00
|
|
|
}
|
2016-05-23 12:33:43 +00:00
|
|
|
if a.Config.Agent.Debug {
|
|
|
|
log.Printf("Input [%s] gathered metrics, (%s interval) in %s\n",
|
|
|
|
input.Name, interval, elapsed)
|
|
|
|
}
|
2015-05-20 05:19:32 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-shutdown:
|
|
|
|
return nil
|
|
|
|
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{},
|
|
|
|
input *internal_models.RunningInput,
|
|
|
|
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 {
|
|
|
|
log.Printf("ERROR in input [%s]: %s", input.Name, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
case <-ticker.C:
|
|
|
|
log.Printf("ERROR: input [%s] took longer to collect than "+
|
|
|
|
"collection interval (%s)",
|
|
|
|
input.Name, timeout)
|
|
|
|
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-01-27 23:15:14 +00:00
|
|
|
acc := NewAccumulator(input.Config, metricC)
|
2016-05-19 15:36:58 +00:00
|
|
|
acc.SetTrace(true)
|
2016-04-19 01:13:45 +00:00
|
|
|
acc.setDefaultTags(a.Config.Tags)
|
2015-05-20 05:19:32 +00:00
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
fmt.Printf("* Plugin: %s, Collection 1\n", input.Name)
|
|
|
|
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-01-07 20:39:43 +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-01-07 20:39:43 +00:00
|
|
|
fmt.Printf("* Plugin: %s, Collection 2\n", input.Name)
|
|
|
|
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-01-27 21:21:36 +00:00
|
|
|
go func(output *internal_models.RunningOutput) {
|
2016-01-22 18:54:12 +00:00
|
|
|
defer wg.Done()
|
|
|
|
err := output.Write()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error writing to output [%s]: %s\n",
|
|
|
|
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-01-22 18:54:12 +00:00
|
|
|
time.Sleep(time.Millisecond * 200)
|
2015-10-23 17:23:08 +00:00
|
|
|
|
2015-11-26 01:42:07 +00:00
|
|
|
ticker := time.NewTicker(a.Config.Agent.FlushInterval.Duration)
|
2015-10-23 17:23:08 +00:00
|
|
|
|
2015-10-16 22:13:32 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-shutdown:
|
2016-02-16 00:21:38 +00:00
|
|
|
log.Println("Hang on, flushing any cached metrics before shutdown")
|
2016-01-22 18:54:12 +00:00
|
|
|
a.flush()
|
2015-10-16 22:13:32 +00:00
|
|
|
return nil
|
|
|
|
case <-ticker.C:
|
2016-01-22 18:54:12 +00:00
|
|
|
a.flush()
|
2016-01-27 23:15:14 +00:00
|
|
|
case m := <-metricC:
|
2016-01-22 18:54:12 +00:00
|
|
|
for _, o := range a.Config.Outputs {
|
2016-02-16 00:21:38 +00:00
|
|
|
o.AddMetric(m)
|
2016-01-22 18:54:12 +00:00
|
|
|
}
|
2015-10-16 22:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 17:23:08 +00:00
|
|
|
// jitterInterval applies the the interval jitter to the flush interval using
|
|
|
|
// crypto/rand number generator
|
|
|
|
func jitterInterval(ininterval, injitter time.Duration) time.Duration {
|
|
|
|
var jitter int64
|
|
|
|
outinterval := ininterval
|
|
|
|
if injitter.Nanoseconds() != 0 {
|
|
|
|
maxjitter := big.NewInt(injitter.Nanoseconds())
|
2016-01-19 20:00:36 +00:00
|
|
|
if j, err := cryptorand.Int(cryptorand.Reader, maxjitter); err == nil {
|
2015-10-23 17:23:08 +00:00
|
|
|
jitter = j.Int64()
|
|
|
|
}
|
|
|
|
outinterval = time.Duration(jitter + ininterval.Nanoseconds())
|
|
|
|
}
|
|
|
|
|
|
|
|
if outinterval.Nanoseconds() < time.Duration(500*time.Millisecond).Nanoseconds() {
|
|
|
|
log.Printf("Flush interval %s too low, setting to 500ms\n", outinterval)
|
|
|
|
outinterval = time.Duration(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
return outinterval
|
|
|
|
}
|
|
|
|
|
2016-05-25 17:38:25 +00:00
|
|
|
func createAccumulatorForInput(a *Agent, input *internal_models.RunningInput, metricC chan telegraf.Metric) *accumulator {
|
|
|
|
acc := NewAccumulator(input.Config, metricC)
|
|
|
|
acc.SetDebug(a.Config.Agent.Debug)
|
|
|
|
acc.setDefaultTags(a.Config.Tags)
|
|
|
|
return acc
|
|
|
|
}
|
|
|
|
|
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-01-15 19:25:56 +00:00
|
|
|
a.Config.Agent.FlushInterval.Duration = jitterInterval(
|
|
|
|
a.Config.Agent.FlushInterval.Duration,
|
2015-11-26 01:42:07 +00:00
|
|
|
a.Config.Agent.FlushJitter.Duration)
|
2015-10-23 17:23:08 +00:00
|
|
|
|
2016-01-15 19:25:56 +00:00
|
|
|
log.Printf("Agent Config: Interval:%s, Debug:%#v, Quiet:%#v, Hostname:%#v, "+
|
|
|
|
"Flush Interval:%s \n",
|
|
|
|
a.Config.Agent.Interval.Duration, a.Config.Agent.Debug, 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
|
|
|
|
metricC := make(chan telegraf.Metric, 10000)
|
2016-05-27 08:17:11 +00:00
|
|
|
webserver := webserver.NewWebserver(a.Config.Agent.WebhookServiceAddress)
|
2015-10-16 22:13:32 +00:00
|
|
|
|
2016-02-17 21:50:19 +00:00
|
|
|
for _, input := range a.Config.Inputs {
|
|
|
|
// Start service of any ServicePlugins
|
|
|
|
switch p := input.Input.(type) {
|
|
|
|
case telegraf.ServiceInput:
|
2016-05-25 17:38:25 +00:00
|
|
|
acc := createAccumulatorForInput(a, input, metricC)
|
2016-02-17 21:50:19 +00:00
|
|
|
if err := p.Start(acc); err != nil {
|
|
|
|
log.Printf("Service for input %s failed to start, exiting\n%s\n",
|
|
|
|
input.Name, err.Error())
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer p.Stop()
|
2016-05-25 17:38:25 +00:00
|
|
|
case telegraf.WebhookInput:
|
|
|
|
acc := createAccumulatorForInput(a, input, metricC)
|
2016-05-27 08:19:33 +00:00
|
|
|
if err := p.Register(webserver.Router, acc); err != nil {
|
2016-05-25 17:38:25 +00:00
|
|
|
log.Printf("Webhook for input %s failed to start, exiting\n%s\n",
|
|
|
|
input.Name, err.Error())
|
|
|
|
return err
|
|
|
|
}
|
2016-02-17 21:50:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-25 17:38:25 +00:00
|
|
|
webserver.Start()
|
2016-02-17 21:50:19 +00:00
|
|
|
|
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 {
|
2015-10-16 22:13:32 +00:00
|
|
|
log.Printf("Flusher routine failed, exiting: %s\n", err.Error())
|
|
|
|
close(shutdown)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
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-05-19 15:36:58 +00:00
|
|
|
go func(in *internal_models.RunningInput, interv time.Duration) {
|
|
|
|
defer wg.Done()
|
|
|
|
if err := a.gatherer(shutdown, in, interv, metricC); err != nil {
|
|
|
|
log.Printf(err.Error())
|
|
|
|
}
|
|
|
|
}(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
|
|
|
}
|