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

@ -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)

View File

@ -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 {