From 0772076378e352a938b40b5508e1bef7008ae4c7 Mon Sep 17 00:00:00 2001 From: Pierre Fersing Date: Mon, 19 Nov 2018 20:53:09 +0100 Subject: [PATCH] Allow for force gathering ES cluster stats (#4345) --- etc/telegraf.conf | 6 ++-- plugins/inputs/elasticsearch/README.md | 6 ++-- plugins/inputs/elasticsearch/elasticsearch.go | 28 +++++++++++-------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/etc/telegraf.conf b/etc/telegraf.conf index 82df5cdb1..161754f6f 100644 --- a/etc/telegraf.conf +++ b/etc/telegraf.conf @@ -1907,10 +1907,12 @@ # ## - cluster # # cluster_health_level = "indices" # -# ## Set cluster_stats to true when you want to also obtain cluster stats from the -# ## Master node. +# ## Set cluster_stats to true when you want to also obtain cluster stats. # cluster_stats = false # +# ## Only gather cluster_stats from the master node. To work this require local = true +# cluster_stats_only_from_master = true +# # ## node_stats is a list of sub-stats that you want to have gathered. Valid options # ## are "indices", "os", "process", "jvm", "thread_pool", "fs", "transport", "http", # ## "breaker". Per default, all stats are gathered. diff --git a/plugins/inputs/elasticsearch/README.md b/plugins/inputs/elasticsearch/README.md index e88c3f4d6..d8e43da38 100644 --- a/plugins/inputs/elasticsearch/README.md +++ b/plugins/inputs/elasticsearch/README.md @@ -29,10 +29,12 @@ or [cluster-stats](https://www.elastic.co/guide/en/elasticsearch/reference/curre ## - cluster # cluster_health_level = "indices" - ## Set cluster_stats to true when you want to also obtain cluster stats from the - ## Master node. + ## Set cluster_stats to true when you want to also obtain cluster stats. cluster_stats = false + ## Only gather cluster_stats from the master node. To work this require local = true + cluster_stats_only_from_master = true + ## node_stats is a list of sub-stats that you want to have gathered. Valid options ## are "indices", "os", "process", "jvm", "thread_pool", "fs", "transport", "http", ## "breaker". Per default, all stats are gathered. diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index 9875b68aa..479bfcfda 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -104,10 +104,12 @@ const sampleConfig = ` ## - cluster # cluster_health_level = "indices" - ## Set cluster_stats to true when you want to also obtain cluster stats from the - ## Master node. + ## Set cluster_stats to true when you want to also obtain cluster stats. cluster_stats = false + ## Only gather cluster_stats from the master node. To work this require local = true + cluster_stats_only_from_master = true + ## node_stats is a list of sub-stats that you want to have gathered. Valid options ## are "indices", "os", "process", "jvm", "thread_pool", "fs", "transport", "http", ## "breaker". Per default, all stats are gathered. @@ -124,13 +126,14 @@ const sampleConfig = ` // Elasticsearch is a plugin to read stats from one or many Elasticsearch // servers. type Elasticsearch struct { - Local bool - Servers []string - HttpTimeout internal.Duration - ClusterHealth bool - ClusterHealthLevel string - ClusterStats bool - NodeStats []string + Local bool + Servers []string + HttpTimeout internal.Duration + ClusterHealth bool + ClusterHealthLevel string + ClusterStats bool + ClusterStatsOnlyFromMaster bool + NodeStats []string tls.ClientConfig client *http.Client @@ -141,8 +144,9 @@ type Elasticsearch struct { // NewElasticsearch return a new instance of Elasticsearch func NewElasticsearch() *Elasticsearch { return &Elasticsearch{ - HttpTimeout: internal.Duration{Duration: time.Second * 5}, - ClusterHealthLevel: "indices", + HttpTimeout: internal.Duration{Duration: time.Second * 5}, + ClusterStatsOnlyFromMaster: true, + ClusterHealthLevel: "indices", } } @@ -216,7 +220,7 @@ func (e *Elasticsearch) Gather(acc telegraf.Accumulator) error { } } - if e.ClusterStats && e.isMaster { + if e.ClusterStats && (e.isMaster || !e.ClusterStatsOnlyFromMaster || !e.Local) { if err := e.gatherClusterStats(s+"/_cluster/stats", acc); err != nil { acc.AddError(fmt.Errorf(mask.ReplaceAllString(err.Error(), "http(s)://XXX:XXX@"))) return