Skip to content

Commit

Permalink
Merge pull request #16 from vinted/feature/add_noout_flag_metric
Browse files Browse the repository at this point in the history
Add noout flag metric
  • Loading branch information
Seitanas authored Feb 13, 2020
2 parents 98fa017 + 2aa6aa6 commit 25960ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ceph_health_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"regexp"
"strconv"
"strings"
)

type cephHealthStats struct {
Expand Down Expand Up @@ -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
Expand All @@ -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"}
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ceph_health_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 25960ca

Please sign in to comment.