parent
e910a03af4
commit
f2ab5f61f5
|
@ -2,8 +2,11 @@ package elasticsearch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
|
@ -93,21 +96,41 @@ func (e *Elasticsearch) Description() string {
|
||||||
// Gather reads the stats from Elasticsearch and writes it to the
|
// Gather reads the stats from Elasticsearch and writes it to the
|
||||||
// Accumulator.
|
// Accumulator.
|
||||||
func (e *Elasticsearch) Gather(acc inputs.Accumulator) error {
|
func (e *Elasticsearch) Gather(acc inputs.Accumulator) error {
|
||||||
|
errChan := make(chan error, len(e.Servers))
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(len(e.Servers))
|
||||||
|
|
||||||
for _, serv := range e.Servers {
|
for _, serv := range e.Servers {
|
||||||
|
go func(s string, acc inputs.Accumulator) {
|
||||||
|
defer wg.Done()
|
||||||
var url string
|
var url string
|
||||||
if e.Local {
|
if e.Local {
|
||||||
url = serv + statsPathLocal
|
url = s + statsPathLocal
|
||||||
} else {
|
} else {
|
||||||
url = serv + statsPath
|
url = s + statsPath
|
||||||
}
|
}
|
||||||
if err := e.gatherNodeStats(url, acc); err != nil {
|
if err := e.gatherNodeStats(url, acc); err != nil {
|
||||||
return err
|
errChan <- err
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if e.ClusterHealth {
|
if e.ClusterHealth {
|
||||||
e.gatherClusterStats(fmt.Sprintf("%s/_cluster/health?level=indices", serv), acc)
|
e.gatherClusterStats(fmt.Sprintf("%s/_cluster/health?level=indices", s), acc)
|
||||||
}
|
}
|
||||||
|
}(serv, acc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
close(errChan)
|
||||||
|
// Get all errors and return them as one giant error
|
||||||
|
errStrings := []string{}
|
||||||
|
for err := range errChan {
|
||||||
|
errStrings = append(errStrings, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errStrings) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New(strings.Join(errStrings, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Elasticsearch) gatherNodeStats(url string, acc inputs.Accumulator) error {
|
func (e *Elasticsearch) gatherNodeStats(url string, acc inputs.Accumulator) error {
|
||||||
|
|
Loading…
Reference in New Issue