Skip to content
Snippets Groups Projects
Unverified Commit 5030373a authored by Daniel Nelson's avatar Daniel Nelson Committed by GitHub
Browse files

Reuse transport on next interval in jolokia agent (#4137)

parent 5b599337
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ type JolokiaAgent struct { ...@@ -23,6 +23,7 @@ type JolokiaAgent struct {
Metrics []MetricConfig `toml:"metric"` Metrics []MetricConfig `toml:"metric"`
gatherer *Gatherer gatherer *Gatherer
clients []*Client
} }
func (ja *JolokiaAgent) SampleConfig() string { func (ja *JolokiaAgent) SampleConfig() string {
...@@ -60,20 +61,27 @@ func (ja *JolokiaAgent) Gather(acc telegraf.Accumulator) error { ...@@ -60,20 +61,27 @@ func (ja *JolokiaAgent) Gather(acc telegraf.Accumulator) error {
ja.gatherer = NewGatherer(ja.createMetrics()) ja.gatherer = NewGatherer(ja.createMetrics())
} }
var wg sync.WaitGroup // Initialize clients once
if ja.clients == nil {
for _, url := range ja.URLs { ja.clients = make([]*Client, 0, len(ja.URLs))
client, err := ja.createClient(url) for _, url := range ja.URLs {
if err != nil { client, err := ja.createClient(url)
acc.AddError(fmt.Errorf("Unable to create client for %s: %v", url, err)) if err != nil {
continue 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) wg.Add(1)
go func(client *Client) { go func(client *Client) {
defer wg.Done() defer wg.Done()
err = ja.gatherer.Gather(client, acc) err := ja.gatherer.Gather(client, acc)
if err != nil { if err != nil {
acc.AddError(fmt.Errorf("Unable to gather metrics for %s: %v", client.URL, err)) acc.AddError(fmt.Errorf("Unable to gather metrics for %s: %v", client.URL, err))
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment