From 9fbe08720989bf0e8fe274ab24677aaf205bfae3 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Tue, 13 Jun 2017 00:25:56 -0400 Subject: [PATCH] Further health metrics v2 (#60) * Updated the cluster heatlh state to report 0,1,2 * Clean up cluster health per code review. --- exporter.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/exporter.go b/exporter.go index 0d2c37b0..ca03f27a 100644 --- a/exporter.go +++ b/exporter.go @@ -200,6 +200,18 @@ var ( prometheus.BuildFQName(namespace, "cluster_health", "status_is_green"), "Whether all primary and replica shards are allocated.", []string{"cluster"}, nil) + clusterHealthStatusDesc = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "cluster_health", "status"), + "Whether all primary and replica shards are allocated.", + []string{"cluster", "color"}, nil) + clusterHealthStatusIsYellowDesc = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "cluster_health", "status_is_yellow"), + "Whether all primary and replica shards are allocated.", + []string{"cluster"}, nil) + clusterHealthStatusIsRedDesc = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "cluster_health", "status_is_red"), + "Whether all primary and replica shards are allocated.", + []string{"cluster"}, nil) clusterHealthTimedOutDesc = prometheus.NewDesc( prometheus.BuildFQName(namespace, "cluster_health", "timed_out"), "XXX WHAT DOES THIS MEAN?", @@ -552,11 +564,22 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { ch <- prometheus.MustNewConstMetric(clusterHealthRelocatingShardsDesc, prometheus.GaugeValue, float64(clusterHealth.RelocatingShards), clusterHealth.ClusterName) ch <- prometheus.MustNewConstMetric(clusterHealthUnassignedShardsDesc, prometheus.GaugeValue, float64(clusterHealth.UnassignedShards), clusterHealth.ClusterName) - statusIsGreen := 0.0 - if clusterHealth.Status == "green" { + var statusIsGreen, statusIsYellow, statusIsRed, healthStatus float64 + switch clusterHealth.Status { + case "green": statusIsGreen = 1.0 + healthStatus = 0.0 + case "yellow": + statusIsYellow = 1.0 + healthStatus = 1.0 + case "red": + statusIsRed = 1.0 + healthStatus = 2.0 } ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsGreenDesc, prometheus.GaugeValue, statusIsGreen, clusterHealth.ClusterName) + ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsYellowDesc, prometheus.GaugeValue, statusIsYellow, clusterHealth.ClusterName) + ch <- prometheus.MustNewConstMetric(clusterHealthStatusIsRedDesc, prometheus.GaugeValue, statusIsRed, clusterHealth.ClusterName) + ch <- prometheus.MustNewConstMetric(clusterHealthStatusDesc, prometheus.GaugeValue, healthStatus, clusterHealth.ClusterName, clusterHealth.Status) timedOut := 0.0 if clusterHealth.TimedOut {