Skip to content

Commit a12a6b5

Browse files
author
Neil Brookes
authored
Merge pull request prometheus-community#1 from objectrocket/fix_cluster_health_metic
Updated the cluster heatlh state to report 0,1,2
2 parents 887619e + 5b7b899 commit a12a6b5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

exporter.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ var (
170170
prometheus.BuildFQName(namespace, "cluster_health", "status_is_green"),
171171
"Whether all primary and replica shards are allocated.",
172172
[]string{"cluster"}, nil)
173+
clusterHealthStatusDesc = prometheus.NewDesc(
174+
prometheus.BuildFQName(namespace, "cluster_health", "status"),
175+
"Whether all primary and replica shards are allocated.",
176+
[]string{"cluster","color"}, nil)
177+
clusterHealthStatusIsYellowDesc = prometheus.NewDesc(
178+
prometheus.BuildFQName(namespace, "cluster_health", "status_is_yellow"),
179+
"Whether all primary and replica shards are allocated.",
180+
[]string{"cluster"}, nil)
181+
clusterHealthStatusIsRedDesc = prometheus.NewDesc(
182+
prometheus.BuildFQName(namespace, "cluster_health", "status_is_red"),
183+
"Whether all primary and replica shards are allocated.",
184+
[]string{"cluster"}, nil)
173185
clusterHealthTimedOutDesc = prometheus.NewDesc(
174186
prometheus.BuildFQName(namespace, "cluster_health", "timed_out"),
175187
"XXX WHAT DOES THIS MEAN?",
@@ -488,12 +500,29 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
488500
ch <- prometheus.MustNewConstMetric(clusterHealthRelocatingShardsDesc, prometheus.GaugeValue, float64(clusterHealth.RelocatingShards), clusterHealth.ClusterName)
489501
ch <- prometheus.MustNewConstMetric(clusterHealthUnassignedShardsDesc, prometheus.GaugeValue, float64(clusterHealth.UnassignedShards), clusterHealth.ClusterName)
490502

503+
healthStatus := 0.0
491504
statusIsGreen := 0.0
492505
if clusterHealth.Status == "green" {
493506
statusIsGreen = 1.0
507+
healthStatus = 0.0
494508
}
495509
ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsGreenDesc, prometheus.GaugeValue, statusIsGreen, clusterHealth.ClusterName)
496510

511+
statusIsYellow := 0.0
512+
if clusterHealth.Status == "yellow" {
513+
statusIsYellow = 1.0
514+
healthStatus = 1.0
515+
}
516+
ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsYellowDesc, prometheus.GaugeValue, statusIsYellow, clusterHealth.ClusterName)
517+
518+
statusIsRed := 0.0
519+
if clusterHealth.Status == "red" {
520+
statusIsRed = 1.0
521+
healthStatus = 2.0
522+
}
523+
ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsRedDesc, prometheus.GaugeValue, statusIsRed, clusterHealth.ClusterName)
524+
ch <- prometheus.MustNewConstMetric(clusterHealthStatusDesc,prometheus.GaugeValue,healthStatus,clusterHealth.ClusterName,clusterHealth.Status)
525+
497526
timedOut := 0.0
498527
if clusterHealth.TimedOut {
499528
timedOut = 1.0

0 commit comments

Comments
 (0)