From 2aa6aa60ef74ffb8e8795ea52cf29b83b0707629 Mon Sep 17 00:00:00 2001 From: Tadas Date: Thu, 13 Feb 2020 16:08:21 +0200 Subject: [PATCH] Add noout flag metric --- ceph_health_collector.go | 14 +++++++++++++- ceph_health_collector_test.go | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ceph_health_collector.go b/ceph_health_collector.go index c0d12ca..c66e20e 100644 --- a/ceph_health_collector.go +++ b/ceph_health_collector.go @@ -7,6 +7,7 @@ import ( "os/exec" "regexp" "strconv" + "strings" ) type cephHealthStats struct { @@ -53,6 +54,7 @@ func CephHealthCollector() map[string]cephHealthData { var healthString string var cephHealthStatus float64 var cephHealthStatusString string + var nooutFlag float64 if stats.Health.Status != "" { cephHealthStatusString = stats.Health.Status @@ -72,6 +74,7 @@ func CephHealthCollector() map[string]cephHealthData { } healthData["ceph_cluster_health_status"] = cephHealthData{value: cephHealthStatus, metricType: GaugeValue, help: "Ceph cluster health status (ok:0, warning:1, error:2)"} + healthData["ceph_cluster_noout_flag"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Status of noout flag (0:unset, 1:set)"} healthData["ceph_cluster_pgs_degraded"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Number of degraded PGs"} healthData["ceph_cluster_pgs_undersized"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Number of undersized PGs"} @@ -83,7 +86,7 @@ func CephHealthCollector() map[string]cephHealthData { healthData["ceph_cluster_pgs_recovery_wait"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Number of PGs waiting for recovery"} healthData["ceph_cluster_pgs_peering"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Number of peering PGs"} healthData["ceph_cluster_objects_degraded"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Number of degraded objects in a cluster"} - healthData["ceph_cluster_objects_misplaced"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Number of mislpaced objects in a cluster"} + healthData["ceph_cluster_objects_misplaced"] = cephHealthData{value: 0, metricType: GaugeValue, help: "Number of misplaced objects in a cluster"} // Check if using new Nautilus status data structure. if stats.Health.Checks != nil { @@ -96,6 +99,15 @@ func CephHealthCollector() map[string]cephHealthData { healthString = fmt.Sprintf("%v", stats.Health.Summary) } + if strings.Contains(healthString, "noout flag(s) set") { + nooutFlag = 1 + } else { + nooutFlag = 0 + } + var tmp = healthData["ceph_cluster_noout_flag"] + tmp.value = float64(nooutFlag) + healthData["ceph_cluster_noout_flag"] = tmp + // Do regex match against status string and build metrics re := regexp.MustCompile(`([\d]+) pgs degraded`) result := re.FindStringSubmatch(healthString) diff --git a/ceph_health_collector_test.go b/ceph_health_collector_test.go index 1be5937..bf30758 100644 --- a/ceph_health_collector_test.go +++ b/ceph_health_collector_test.go @@ -40,4 +40,7 @@ func TestCephHealthCollector(t *testing.T) { if reflect.TypeOf(health["ceph_cluster_objects_misplaced"]).String() != "main.cephHealthData" { t.Errorf("health[ceph_cluster_objects_misplaced] has wrong data") } + if reflect.TypeOf(health["ceph_cluster_noout_flag"]).String() != "main.cephHealthData" { + t.Errorf("health[ceph_cluster_noout_flag] has wrong data") + } }