Skip to content

Commit 9fbe087

Browse files
jmcarpdominikschulz
authored andcommitted
Further health metrics v2 (#60)
* Updated the cluster heatlh state to report 0,1,2 * Clean up cluster health per code review.
1 parent 318cef3 commit 9fbe087

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

exporter.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ var (
200200
prometheus.BuildFQName(namespace, "cluster_health", "status_is_green"),
201201
"Whether all primary and replica shards are allocated.",
202202
[]string{"cluster"}, nil)
203+
clusterHealthStatusDesc = prometheus.NewDesc(
204+
prometheus.BuildFQName(namespace, "cluster_health", "status"),
205+
"Whether all primary and replica shards are allocated.",
206+
[]string{"cluster", "color"}, nil)
207+
clusterHealthStatusIsYellowDesc = prometheus.NewDesc(
208+
prometheus.BuildFQName(namespace, "cluster_health", "status_is_yellow"),
209+
"Whether all primary and replica shards are allocated.",
210+
[]string{"cluster"}, nil)
211+
clusterHealthStatusIsRedDesc = prometheus.NewDesc(
212+
prometheus.BuildFQName(namespace, "cluster_health", "status_is_red"),
213+
"Whether all primary and replica shards are allocated.",
214+
[]string{"cluster"}, nil)
203215
clusterHealthTimedOutDesc = prometheus.NewDesc(
204216
prometheus.BuildFQName(namespace, "cluster_health", "timed_out"),
205217
"XXX WHAT DOES THIS MEAN?",
@@ -552,11 +564,22 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
552564
ch <- prometheus.MustNewConstMetric(clusterHealthRelocatingShardsDesc, prometheus.GaugeValue, float64(clusterHealth.RelocatingShards), clusterHealth.ClusterName)
553565
ch <- prometheus.MustNewConstMetric(clusterHealthUnassignedShardsDesc, prometheus.GaugeValue, float64(clusterHealth.UnassignedShards), clusterHealth.ClusterName)
554566

555-
statusIsGreen := 0.0
556-
if clusterHealth.Status == "green" {
567+
var statusIsGreen, statusIsYellow, statusIsRed, healthStatus float64
568+
switch clusterHealth.Status {
569+
case "green":
557570
statusIsGreen = 1.0
571+
healthStatus = 0.0
572+
case "yellow":
573+
statusIsYellow = 1.0
574+
healthStatus = 1.0
575+
case "red":
576+
statusIsRed = 1.0
577+
healthStatus = 2.0
558578
}
559579
ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsGreenDesc, prometheus.GaugeValue, statusIsGreen, clusterHealth.ClusterName)
580+
ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsYellowDesc, prometheus.GaugeValue, statusIsYellow, clusterHealth.ClusterName)
581+
ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsRedDesc, prometheus.GaugeValue, statusIsRed, clusterHealth.ClusterName)
582+
ch <- prometheus.MustNewConstMetric(clusterHealthStatusDesc, prometheus.GaugeValue, healthStatus, clusterHealth.ClusterName, clusterHealth.Status)
560583

561584
timedOut := 0.0
562585
if clusterHealth.TimedOut {

0 commit comments

Comments
 (0)