Reuse transport on next interval in jolokia agent (#4137)
This commit is contained in:
parent
59a2f2e7f4
commit
b703215bad
|
@ -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 {
|
||||||
ja.gatherer = NewGatherer(ja.createMetrics())
|
ja.gatherer = NewGatherer(ja.createMetrics())
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
// Initialize clients once
|
||||||
|
if ja.clients == nil {
|
||||||
|
ja.clients = make([]*Client, 0, len(ja.URLs))
|
||||||
for _, url := range ja.URLs {
|
for _, url := range ja.URLs {
|
||||||
client, err := ja.createClient(url)
|
client, err := ja.createClient(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("Unable to create client for %s: %v", url, err))
|
acc.AddError(fmt.Errorf("Unable to create client for %s: %v", url, err))
|
||||||
continue
|
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))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue