Skip to content

Commit

Permalink
Add node roles tag to elasticsearch input (#6064)
Browse files Browse the repository at this point in the history
  • Loading branch information
dupondje authored and danielnelson committed Jul 3, 2019
1 parent f7e85eb commit 9af39bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/inputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"
"regexp"
"sort"
"strings"
"sync"
"time"
Expand All @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/elasticsearch/testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const nodeStatsResponse = `
"inet[/127.0.0.1:9300]",
"NONE"
],
"roles": [
"master",
"data",
"ingest"
],
"attributes": {
"master": "true"
},
Expand Down Expand Up @@ -945,6 +950,11 @@ const nodeStatsResponseJVMProcess = `
"inet[/127.0.0.1:9300]",
"NONE"
],
"roles": [
"master",
"data",
"ingest"
],
"attributes": {
"master": "true"
},
Expand Down

0 comments on commit 9af39bb

Please sign in to comment.