add elasticsearch_up metric

This commit is contained in:
Ulric Qin 2022-06-29 07:49:46 +08:00
parent 9b0596c73a
commit d0747c637f
3 changed files with 13 additions and 6 deletions

View File

@ -3,7 +3,7 @@
############################################################################
# !!! uncomment [[instances]] to enable this plugin
# [[instances]]
[[instances]]
# # interval = global.interval * interval_times
# interval_times = 1
@ -11,7 +11,8 @@
# labels = { cluster="cloud-n9e-es" }
## specify a list of one or more Elasticsearch servers
servers = ["http://localhost:9200"]
# servers = ["http://localhost:9200"]
servers = []
## Timeout for HTTP requests to the elastic search server(s)
http_timeout = "5s"
@ -47,8 +48,8 @@ indices_level = "shards"
# node_stats = ["jvm", "http"]
## HTTP Basic Authentication username and password.
# username = ""
# password = ""
username = "elastic"
password = "password"
## Optional TLS Config
# use_tls = false

View File

@ -5,7 +5,7 @@
# For more details, see the OpenTelemetry official docs:
# https://opentelemetry.io/docs/collector/configuration/
traces:
enable: true
enable: false
extensions:
health_check:
pprof:

View File

@ -2,6 +2,7 @@ package elasticsearch
import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
@ -111,7 +112,9 @@ func (r *Elasticsearch) Init() error {
for i := 0; i < len(r.Instances); i++ {
if err := r.Instances[i].Init(); err != nil {
return err
if !errors.Is(err, types.ErrInstancesEmpty) {
return err
}
}
}
@ -229,6 +232,7 @@ func (ins *Instance) gatherOnce(slist *list.SafeList) {
// Gather node ID
if info.nodeID, err = ins.gatherNodeID(s + "/_nodes/_local/name"); err != nil {
slist.PushFront(inputs.NewSample("up", 0, ins.Labels))
log.Println("E! failed to gather node id:", err)
return
}
@ -236,10 +240,12 @@ func (ins *Instance) gatherOnce(slist *list.SafeList) {
// get cat/master information here so NodeStats can determine
// whether this node is the Master
if info.masterID, err = ins.getCatMaster(s + "/_cat/master"); err != nil {
slist.PushFront(inputs.NewSample("up", 0, ins.Labels))
log.Println("E! failed to get cat master:", err)
return
}
slist.PushFront(inputs.NewSample("up", 1, ins.Labels))
ins.serverInfoMutex.Lock()
ins.serverInfo[s] = info
ins.serverInfoMutex.Unlock()