Skip to content

Commit

Permalink
Reuse transport on next interval in jolokia agent (#4137)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored May 12, 2018
1 parent 5b59933 commit 5030373
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions plugins/inputs/jolokia2/jolokia_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type JolokiaAgent struct {

Metrics []MetricConfig `toml:"metric"`
gatherer *Gatherer
clients []*Client
}

func (ja *JolokiaAgent) SampleConfig() string {
Expand Down Expand Up @@ -60,20 +61,27 @@ func (ja *JolokiaAgent) Gather(acc telegraf.Accumulator) error {
ja.gatherer = NewGatherer(ja.createMetrics())
}

var wg sync.WaitGroup

for _, url := range ja.URLs {
client, err := ja.createClient(url)
if err != nil {
acc.AddError(fmt.Errorf("Unable to create client for %s: %v", url, err))
continue
// Initialize clients once
if ja.clients == nil {
ja.clients = make([]*Client, 0, len(ja.URLs))
for _, url := range ja.URLs {
client, err := ja.createClient(url)
if err != nil {
acc.AddError(fmt.Errorf("Unable to create client for %s: %v", url, err))
continue
}
ja.clients = append(ja.clients, client)
}
}

var wg sync.WaitGroup

for _, client := range ja.clients {
wg.Add(1)
go func(client *Client) {
defer wg.Done()

err = ja.gatherer.Gather(client, acc)
err := ja.gatherer.Gather(client, acc)
if err != nil {
acc.AddError(fmt.Errorf("Unable to gather metrics for %s: %v", client.URL, err))
}
Expand Down

0 comments on commit 5030373

Please sign in to comment.