From d0747c637fe919d1da0c1fe903b5fd6770944b25 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Wed, 29 Jun 2022 07:49:46 +0800 Subject: [PATCH] add elasticsearch_up metric --- conf/input.elasticsearch/elasticsearch.toml | 9 +++++---- conf/traces.yaml | 2 +- inputs/elasticsearch/elasticsearch.go | 8 +++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/conf/input.elasticsearch/elasticsearch.toml b/conf/input.elasticsearch/elasticsearch.toml index 7d27b92..cfb097b 100644 --- a/conf/input.elasticsearch/elasticsearch.toml +++ b/conf/input.elasticsearch/elasticsearch.toml @@ -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 diff --git a/conf/traces.yaml b/conf/traces.yaml index b9b83f4..49f6586 100644 --- a/conf/traces.yaml +++ b/conf/traces.yaml @@ -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: diff --git a/inputs/elasticsearch/elasticsearch.go b/inputs/elasticsearch/elasticsearch.go index 4c31f07..8345750 100644 --- a/inputs/elasticsearch/elasticsearch.go +++ b/inputs/elasticsearch/elasticsearch.go @@ -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()