From 6c87148cd401de996422905bd4a6af4354cb3096 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Thu, 9 Jul 2015 18:41:16 +0200 Subject: [PATCH] Add node-id and node attributes to tags. --- plugins/elasticsearch/elasticsearch.go | 14 ++++++++++---- plugins/elasticsearch/elasticsearch_test.go | 8 +++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/elasticsearch/elasticsearch.go b/plugins/elasticsearch/elasticsearch.go index 6294bcaaf..9958b01a6 100644 --- a/plugins/elasticsearch/elasticsearch.go +++ b/plugins/elasticsearch/elasticsearch.go @@ -12,9 +12,10 @@ const indicesStatsPath = "/_nodes/stats/indices" const indicesStatsPathLocal = "/_nodes/_local/stats/indices" type node struct { - Host string `json:"host"` - Name string `json:"name"` - Indices map[string]map[string]interface{} `json:"indices"` + Host string `json:"host"` + Name string `json:"name"` + Attributes map[string]string `json:"attributes"` + Indices map[string]map[string]interface{} `json:"indices"` } const sampleConfig = ` @@ -83,13 +84,18 @@ func (e *Elasticsearch) gatherUrl(url string, acc plugins.Accumulator) error { return err } - for _, n := range esRes.Nodes { + for id, n := range esRes.Nodes { tags := map[string]string{ + "node_id": id, "node_host": n.Host, "node_name": n.Name, "cluster_name": esRes.ClusterName, } + for k, v := range n.Attributes { + tags["node_attribute_"+k] = v + } + for group, stats := range n.Indices { for statName, value := range stats { floatVal, ok := value.(float64) diff --git a/plugins/elasticsearch/elasticsearch_test.go b/plugins/elasticsearch/elasticsearch_test.go index 417f3829e..e5b2cfb79 100644 --- a/plugins/elasticsearch/elasticsearch_test.go +++ b/plugins/elasticsearch/elasticsearch_test.go @@ -248,9 +248,11 @@ func TestElasticsearch(t *testing.T) { } tags := map[string]string{ - "node_host": "test", - "node_name": "test.host.com", - "cluster_name": "es-testcluster", + "cluster_name": "es-testcluster", + "node_attribute_master": "true", + "node_id": "SDFsfSDFsdfFSDSDfSFDSDF", + "node_name": "test.host.com", + "node_host": "test", } for key, val := range indicesExpected {