Add node-id and node attributes to tags.

This commit is contained in:
Orne Brocaar 2015-07-09 18:41:16 +02:00
parent 3f6c46e1ec
commit 6c87148cd4
2 changed files with 15 additions and 7 deletions

View File

@ -14,6 +14,7 @@ const indicesStatsPathLocal = "/_nodes/_local/stats/indices"
type node struct { type node struct {
Host string `json:"host"` Host string `json:"host"`
Name string `json:"name"` Name string `json:"name"`
Attributes map[string]string `json:"attributes"`
Indices map[string]map[string]interface{} `json:"indices"` Indices map[string]map[string]interface{} `json:"indices"`
} }
@ -83,13 +84,18 @@ func (e *Elasticsearch) gatherUrl(url string, acc plugins.Accumulator) error {
return err return err
} }
for _, n := range esRes.Nodes { for id, n := range esRes.Nodes {
tags := map[string]string{ tags := map[string]string{
"node_id": id,
"node_host": n.Host, "node_host": n.Host,
"node_name": n.Name, "node_name": n.Name,
"cluster_name": esRes.ClusterName, "cluster_name": esRes.ClusterName,
} }
for k, v := range n.Attributes {
tags["node_attribute_"+k] = v
}
for group, stats := range n.Indices { for group, stats := range n.Indices {
for statName, value := range stats { for statName, value := range stats {
floatVal, ok := value.(float64) floatVal, ok := value.(float64)

View File

@ -248,9 +248,11 @@ func TestElasticsearch(t *testing.T) {
} }
tags := map[string]string{ 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 { for key, val := range indicesExpected {