Add node roles tag to elasticsearch input (#6064)

This commit is contained in:
dupondje 2019-07-03 22:04:07 +02:00 committed by Daniel Nelson
parent f7e85ebac2
commit 9af39bbb7d
3 changed files with 15 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"
"regexp"
"sort"
"strings"
"sync"
"time"
@ -27,6 +28,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"`
@ -326,11 +328,13 @@ 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,
"node_name": n.Name,
"cluster_name": nodeStats.ClusterName,
"node_roles": strings.Join(n.Roles, ","),
}
for k, v := range n.Attributes {

View File

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

View File

@ -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"
},