Skip to content

Commit

Permalink
Further health metrics v2 (#60)
Browse files Browse the repository at this point in the history
* Updated the cluster heatlh state to report 0,1,2

* Clean up cluster health per code review.
  • Loading branch information
jmcarp authored and dominikschulz committed Jun 13, 2017
1 parent 318cef3 commit 9fbe087
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9fbe087

Please sign in to comment.