Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmm-sumo committed Feb 18, 2021
1 parent 660eb5b commit 1ce1324
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,44 @@ func (a *Agent) Run(ctx context.Context) error {
return err
}

// RunWithChannel starts inputs and passes all gathered metrics into the passed
// channel.
func (a *Agent) RunWithChannel(ctx context.Context, out chan<- telegraf.Metric) error {
log.Printf("I! [agent] Config: Interval:%s, Quiet:%#v, Hostname:%#v, "+
"Flush Interval:%s",
a.Config.Agent.Interval.Duration, a.Config.Agent.Quiet,
a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration,
)

log.Printf("D! [agent] Initializing plugins")
err := a.initPlugins()
if err != nil {
return err
}

startTime := time.Now()

iu, err := a.startInputs(out, a.Config.Inputs)
if err != nil {
return err
}

var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
err := a.runInputs(ctx, startTime, iu)
if err != nil {
log.Printf("E! [agent] Error running inputs: %v", err)
}
}()

wg.Wait()

log.Printf("D! [agent] Stopped Successfully")
return err
}

// initPlugins runs the Init function on plugins.
func (a *Agent) initPlugins() error {
for _, input := range a.Config.Inputs {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,5 @@ require (

// replaced due to https://github.com/satori/go.uuid/issues/73
replace github.com/satori/go.uuid => github.com/gofrs/uuid v3.2.0+incompatible

replace github.com/influxdata/telegraf => ./

0 comments on commit 1ce1324

Please sign in to comment.