From 1775e1cdc692ae08cfad7668b02807cea3bd4ed3 Mon Sep 17 00:00:00 2001 From: dupondje Date: Mon, 17 Jun 2019 22:31:15 +0200 Subject: [PATCH] Add cluster name tag to elasticsearch indices (#5998) --- plugins/inputs/elasticsearch/elasticsearch.go | 4 +++- plugins/inputs/elasticsearch/elasticsearch_test.go | 4 ++-- plugins/inputs/elasticsearch/testdata_test.go | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index 479bfcfdadefc..13c567b30605a 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -50,6 +50,7 @@ type clusterHealth struct { RelocatingShards int `json:"relocating_shards"` InitializingShards int `json:"initializing_shards"` UnassignedShards int `json:"unassigned_shards"` + DelayedUnassignedShards int `json:"delayed_unassigned_shards"` NumberOfPendingTasks int `json:"number_of_pending_tasks"` TaskMaxWaitingInQueueMillis int `json:"task_max_waiting_in_queue_millis"` ActiveShardsPercentAsNumber float64 `json:"active_shards_percent_as_number"` @@ -340,6 +341,7 @@ func (e *Elasticsearch) gatherClusterHealth(url string, acc telegraf.Accumulator "relocating_shards": healthStats.RelocatingShards, "initializing_shards": healthStats.InitializingShards, "unassigned_shards": healthStats.UnassignedShards, + "delayed_unassigned_shards": healthStats.DelayedUnassignedShards, "number_of_pending_tasks": healthStats.NumberOfPendingTasks, "task_max_waiting_in_queue_millis": healthStats.TaskMaxWaitingInQueueMillis, "active_shards_percent_as_number": healthStats.ActiveShardsPercentAsNumber, @@ -366,7 +368,7 @@ func (e *Elasticsearch) gatherClusterHealth(url string, acc telegraf.Accumulator acc.AddFields( "elasticsearch_indices", indexFields, - map[string]string{"index": name}, + map[string]string{"index": name, "name": healthStats.ClusterName}, measurementTime, ) } diff --git a/plugins/inputs/elasticsearch/elasticsearch_test.go b/plugins/inputs/elasticsearch/elasticsearch_test.go index 1616bfeb23e7e..ec6951fbdbcda 100644 --- a/plugins/inputs/elasticsearch/elasticsearch_test.go +++ b/plugins/inputs/elasticsearch/elasticsearch_test.go @@ -190,11 +190,11 @@ func TestGatherClusterHealthAlsoIndicesHealth(t *testing.T) { acc.AssertContainsTaggedFields(t, "elasticsearch_indices", v1IndexExpected, - map[string]string{"index": "v1"}) + map[string]string{"index": "v1", "name": "elasticsearch_telegraf"}) acc.AssertContainsTaggedFields(t, "elasticsearch_indices", v2IndexExpected, - map[string]string{"index": "v2"}) + map[string]string{"index": "v2", "name": "elasticsearch_telegraf"}) } func TestGatherClusterStatsMaster(t *testing.T) { diff --git a/plugins/inputs/elasticsearch/testdata_test.go b/plugins/inputs/elasticsearch/testdata_test.go index 622abeaf87b44..df50d0a2b942b 100644 --- a/plugins/inputs/elasticsearch/testdata_test.go +++ b/plugins/inputs/elasticsearch/testdata_test.go @@ -12,6 +12,7 @@ const clusterHealthResponse = ` "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, + "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100.0 @@ -30,6 +31,7 @@ const clusterHealthResponseWithIndices = ` "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, + "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100.0, @@ -69,6 +71,7 @@ var clusterHealthExpected = map[string]interface{}{ "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, + "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100.0,