Skip to content

Commit

Permalink
Merge pull request #105 from zwopir/feature/fix_role_labels_es2x
Browse files Browse the repository at this point in the history
fix role labels for ES 2.x
  • Loading branch information
zwopir authored Oct 30, 2017
2 parents fb90a0d + 15f3973 commit 1bd5c3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions collector/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,53 @@ import (
)

var (
defaultNodeLabels = []string{"cluster", "host", "name", "es_master_node", "es_data_node", "es_ingest_node"}
defaultNodeLabels = []string{"cluster", "host", "name", "es_master_node", "es_data_node", "es_ingest_node", "es_client_node"}
defaultThreadPoolLabels = append(defaultNodeLabels, "type")
defaultBreakerLabels = append(defaultNodeLabels, "breaker")
defaultFilesystemLabels = append(defaultNodeLabels, "mount", "path")
defaultCacheLabels = append(defaultNodeLabels, "cache")

defaultNodeLabelValues = func(cluster string, node NodeStatsNodeResponse) []string {
// default settings (2.x) and map, which roles to consider
roles := map[string]bool{
"master": true,
"data": true,
"ingest": true,
"ingest": false,
}
isClientNode := "true"
// assumption: a 5.x node has at least one role, otherwise it's a 1.7 or 2.x node
if len(node.Roles) > 0 {
for _, role := range node.Roles {
// set every absent role to false
if _, ok := roles[role]; !ok {
roles[role] = false
} else {
// if present in the roles field, set to true
roles[role] = true
}
}
} else {
for role, setting := range node.Attributes {
if _, ok := roles[role]; ok {
roles[role] = setting == "false"
if setting == "false" {
roles[role] = false
} else {
roles[role] = true
}
}
}
}
if len(node.Http) == 0 {
isClientNode = "false"
}
return []string{
cluster,
node.Host,
node.Name,
fmt.Sprintf("%t", roles["master"]),
fmt.Sprintf("%t", roles["data"]),
fmt.Sprintf("%t", roles["ingest"]),
isClientNode,
}
}
defaultThreadPoolLabelValues = func(cluster string, node NodeStatsNodeResponse, pool string) []string {
Expand Down
1 change: 1 addition & 0 deletions collector/nodes_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type NodeStatsNodeResponse struct {
ThreadPool map[string]NodeStatsThreadPoolPoolResponse `json:"thread_pool"`
JVM NodeStatsJVMResponse `json:"jvm"`
Breakers map[string]NodeStatsBreakersResponse `json:"breakers"`
Http map[string]int `json:"http"`
Transport NodeStatsTransportResponse `json:"transport"`
Process NodeStatsProcessResponse `json:"process"`
}
Expand Down

0 comments on commit 1bd5c3b

Please sign in to comment.