From db005d50f92060afbec1ee61c8faa74b6de9e293 Mon Sep 17 00:00:00 2001 From: Christophe MORIO Date: Thu, 17 Nov 2022 12:48:40 +0100 Subject: [PATCH 1/3] feat: additional elasticcloud roles Signed-off-by: Christophe MORIO --- collector/nodes.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/collector/nodes.go b/collector/nodes.go index ba93a9b6..8740f3d1 100644 --- a/collector/nodes.go +++ b/collector/nodes.go @@ -29,10 +29,14 @@ import ( func getRoles(node NodeStatsNodeResponse) map[string]bool { // default settings (2.x) and map, which roles to consider roles := map[string]bool{ - "master": false, - "data": false, - "ingest": false, - "client": true, + "master": false, + "data": false, + "data_hot": false, + "data_warm": false, + "data_cold": false, + "data_frozen": false, + "ingest": false, + "client": 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 { @@ -84,7 +88,9 @@ func createRoleMetric(role string) *nodeMetric { } var ( - defaultNodeLabels = []string{"cluster", "host", "name", "es_master_node", "es_data_node", "es_ingest_node", "es_client_node"} + defaultNodeLabels = []string{"cluster", "host", "name", "es_master_node", "es_data_node", + "es_data_hot_node", "es_data_warm_node", "es_data_cold_node", "es_data_frozen_node", + "es_ingest_node", "es_client_node"} defaultRoleLabels = []string{"cluster", "host", "name"} defaultThreadPoolLabels = append(defaultNodeLabels, "type") defaultBreakerLabels = append(defaultNodeLabels, "breaker") @@ -100,6 +106,10 @@ var ( node.Name, fmt.Sprintf("%t", roles["master"]), fmt.Sprintf("%t", roles["data"]), + fmt.Sprintf("%t", roles["data_hot"]), + fmt.Sprintf("%t", roles["data_warm"]), + fmt.Sprintf("%t", roles["data_cold"]), + fmt.Sprintf("%t", roles["data_frozen"]), fmt.Sprintf("%t", roles["ingest"]), fmt.Sprintf("%t", roles["client"]), } @@ -1866,7 +1876,8 @@ func (c *Nodes) Collect(ch chan<- prometheus.Metric) { // Handle the node labels metric roles := getRoles(node) - for _, role := range []string{"master", "data", "client", "ingest"} { + for _, role := range []string{"master", "data", "data_hot", "data_cold", + "data_warm", "data_frozen", "client", "ingest"} { if roles[role] { metric := createRoleMetric(role) ch <- prometheus.MustNewConstMetric( From 00302dceef8ad36333af76748e8b71298a9ebe92 Mon Sep 17 00:00:00 2001 From: Christophe MORIO Date: Mon, 28 Nov 2022 18:04:16 +0100 Subject: [PATCH 2/3] feat: enhance only nodes_roles metrics with non default roles Signed-off-by: Christophe MORIO --- collector/nodes.go | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/collector/nodes.go b/collector/nodes.go index 8740f3d1..31996dc2 100644 --- a/collector/nodes.go +++ b/collector/nodes.go @@ -29,14 +29,18 @@ import ( func getRoles(node NodeStatsNodeResponse) map[string]bool { // default settings (2.x) and map, which roles to consider roles := map[string]bool{ - "master": false, - "data": false, - "data_hot": false, - "data_warm": false, - "data_cold": false, - "data_frozen": false, - "ingest": false, - "client": true, + "master": false, + "data": false, + "data_hot": false, + "data_warm": false, + "data_cold": false, + "data_frozen": false, + "data_content": false, + "ml": false, + "remote_cluster_client": false, + "transform": false, + "ingest": false, + "client": 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 { @@ -71,7 +75,7 @@ func createRoleMetric(role string) *nodeMetric { Type: prometheus.GaugeValue, Desc: prometheus.NewDesc( prometheus.BuildFQName(namespace, "nodes", "roles"), - "Node roles", + "Node default roles", defaultRoleLabels, prometheus.Labels{"role": role}, ), Value: func(node NodeStatsNodeResponse) float64 { @@ -88,9 +92,7 @@ func createRoleMetric(role string) *nodeMetric { } var ( - defaultNodeLabels = []string{"cluster", "host", "name", "es_master_node", "es_data_node", - "es_data_hot_node", "es_data_warm_node", "es_data_cold_node", "es_data_frozen_node", - "es_ingest_node", "es_client_node"} + defaultNodeLabels = []string{"cluster", "host", "name", "es_master_node", "es_data_node", "es_ingest_node", "es_client_node"} defaultRoleLabels = []string{"cluster", "host", "name"} defaultThreadPoolLabels = append(defaultNodeLabels, "type") defaultBreakerLabels = append(defaultNodeLabels, "breaker") @@ -106,10 +108,6 @@ var ( node.Name, fmt.Sprintf("%t", roles["master"]), fmt.Sprintf("%t", roles["data"]), - fmt.Sprintf("%t", roles["data_hot"]), - fmt.Sprintf("%t", roles["data_warm"]), - fmt.Sprintf("%t", roles["data_cold"]), - fmt.Sprintf("%t", roles["data_frozen"]), fmt.Sprintf("%t", roles["ingest"]), fmt.Sprintf("%t", roles["client"]), } @@ -1876,9 +1874,8 @@ func (c *Nodes) Collect(ch chan<- prometheus.Metric) { // Handle the node labels metric roles := getRoles(node) - for _, role := range []string{"master", "data", "data_hot", "data_cold", - "data_warm", "data_frozen", "client", "ingest"} { - if roles[role] { + for role, roleEnabled := range roles { + if roleEnabled { metric := createRoleMetric(role) ch <- prometheus.MustNewConstMetric( metric.Desc, From b6b8ff77e78bc2cc63586268b808cefc7ddc2079 Mon Sep 17 00:00:00 2001 From: Christophe MORIO Date: Mon, 28 Nov 2022 18:07:41 +0100 Subject: [PATCH 3/3] chore: revert undesired change Signed-off-by: Christophe MORIO --- collector/nodes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/nodes.go b/collector/nodes.go index 31996dc2..47ef445a 100644 --- a/collector/nodes.go +++ b/collector/nodes.go @@ -75,7 +75,7 @@ func createRoleMetric(role string) *nodeMetric { Type: prometheus.GaugeValue, Desc: prometheus.NewDesc( prometheus.BuildFQName(namespace, "nodes", "roles"), - "Node default roles", + "Node roles", defaultRoleLabels, prometheus.Labels{"role": role}, ), Value: func(node NodeStatsNodeResponse) float64 {