From ae167922ed8542741616c9dde54f3de1c317b56e Mon Sep 17 00:00:00 2001 From: Jean-Louis Dupond Date: Tue, 2 Jul 2019 09:59:38 +0200 Subject: [PATCH 1/3] Add node_roles as tag (Closes #2158) This adds node_roles as a tag to the exported elasticsearch metrics. For example: node_roles=master\,data\ --- plugins/inputs/elasticsearch/elasticsearch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index 59b21f2cd0626..48119e149a61c 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -27,6 +27,7 @@ const statsPathLocal = "/_nodes/_local/stats" type nodeStat struct { Host string `json:"host"` Name string `json:"name"` + Roles []string `json:"roles"` Attributes map[string]string `json:"attributes"` Indices interface{} `json:"indices"` OS interface{} `json:"os"` @@ -331,6 +332,7 @@ func (e *Elasticsearch) gatherNodeStats(url string, acc telegraf.Accumulator) er "node_host": n.Host, "node_name": n.Name, "cluster_name": nodeStats.ClusterName, + "node_roles": strings.Join(n.Roles, ","), } for k, v := range n.Attributes { From 9b8c8588eb5e53c2010de7884a411ff694879e54 Mon Sep 17 00:00:00 2001 From: Jean-Louis Dupond Date: Wed, 3 Jul 2019 09:51:41 +0200 Subject: [PATCH 2/3] Sort roles --- plugins/inputs/elasticsearch/elasticsearch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index 48119e149a61c..70377320fb733 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/http" "regexp" + "sort" "strings" "sync" "time" @@ -327,6 +328,7 @@ func (e *Elasticsearch) gatherNodeStats(url string, acc telegraf.Accumulator) er } for id, n := range nodeStats.Nodes { + sort.Strings(n.Roles) tags := map[string]string{ "node_id": id, "node_host": n.Host, From 157df3c926ff8ecfa48e38a23747b3b42a274edf Mon Sep 17 00:00:00 2001 From: Jean-Louis Dupond Date: Wed, 3 Jul 2019 10:03:53 +0200 Subject: [PATCH 3/3] Fix tests --- plugins/inputs/elasticsearch/elasticsearch_test.go | 1 + plugins/inputs/elasticsearch/testdata_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/plugins/inputs/elasticsearch/elasticsearch_test.go b/plugins/inputs/elasticsearch/elasticsearch_test.go index 2987841325c19..4bf5c6a5540c2 100644 --- a/plugins/inputs/elasticsearch/elasticsearch_test.go +++ b/plugins/inputs/elasticsearch/elasticsearch_test.go @@ -21,6 +21,7 @@ func defaultTags() map[string]string { "node_id": "SDFsfSDFsdfFSDSDfSFDSDF", "node_name": "test.host.com", "node_host": "test", + "node_roles": "data,ingest,master", } } func defaultServerInfo() serverInfo { diff --git a/plugins/inputs/elasticsearch/testdata_test.go b/plugins/inputs/elasticsearch/testdata_test.go index ffdf9559d3bea..c637bb9a9bd2a 100644 --- a/plugins/inputs/elasticsearch/testdata_test.go +++ b/plugins/inputs/elasticsearch/testdata_test.go @@ -117,6 +117,11 @@ const nodeStatsResponse = ` "inet[/127.0.0.1:9300]", "NONE" ], + "roles": [ + "master", + "data", + "ingest" + ], "attributes": { "master": "true" }, @@ -945,6 +950,11 @@ const nodeStatsResponseJVMProcess = ` "inet[/127.0.0.1:9300]", "NONE" ], + "roles": [ + "master", + "data", + "ingest" + ], "attributes": { "master": "true" },