Split cluster health state by plus sign

PR #226
This commit is contained in:
Daniel R 2023-01-24 17:42:34 -05:00 committed by GitHub
parent a52902054e
commit d8bf71a8fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 15 deletions

View File

@ -922,7 +922,7 @@ func (c *ClusterHealthCollector) collect(ch chan<- prometheus.Metric) error {
"peering": &peeringPGs, "peering": &peeringPGs,
"stale": &stalePGs, "stale": &stalePGs,
"scrubbing": &scrubbingPGs, "scrubbing": &scrubbingPGs,
"scrubbing+deep": &deepScrubbingPGs, "deep_scrubbing": &deepScrubbingPGs,
"recovering": &recoveringPGs, "recovering": &recoveringPGs,
"recovery_wait": &recoveryWaitPGs, "recovery_wait": &recoveryWaitPGs,
"backfilling": &backfillingPGs, "backfilling": &backfillingPGs,
@ -944,7 +944,7 @@ func (c *ClusterHealthCollector) collect(ch chan<- prometheus.Metric) error {
"peering": c.PeeringPGs, "peering": c.PeeringPGs,
"stale": c.StalePGs, "stale": c.StalePGs,
"scrubbing": c.ScrubbingPGs, "scrubbing": c.ScrubbingPGs,
"scrubbing+deep": c.DeepScrubbingPGs, "deep_scrubbing": c.DeepScrubbingPGs,
"recovering": c.RecoveringPGs, "recovering": c.RecoveringPGs,
"recovery_wait": c.RecoveryWaitPGs, "recovery_wait": c.RecoveryWaitPGs,
"backfilling": c.BackfillingPGs, "backfilling": c.BackfillingPGs,
@ -961,27 +961,20 @@ func (c *ClusterHealthCollector) collect(ch chan<- prometheus.Metric) error {
) )
for _, p := range stats.PGMap.PGsByState { for _, p := range stats.PGMap.PGsByState {
for pgState := range pgStateCounterMap { p.States = strings.ReplaceAll(p.States, "scrubbing+deep", "deep_scrubbing")
if strings.Contains(p.States, pgState) { stateArray := strings.Split(p.States, "+")
*pgStateCounterMap[pgState] += p.Count
for _, state := range stateArray {
if count, has := pgStateCounterMap[state]; has {
*count += p.Count
} }
} }
} }
for state, gauge := range pgStateGaugeMap { for state, gauge := range pgStateGaugeMap {
val := *pgStateCounterMap[state] val := *pgStateCounterMap[state]
if state == "scrubbing" {
val -= *pgStateCounterMap["scrubbing+deep"]
}
if state == "snaptrim" {
val -= *pgStateCounterMap["snaptrim_wait"]
}
ch <- prometheus.MustNewConstMetric(gauge, prometheus.GaugeValue, val) ch <- prometheus.MustNewConstMetric(gauge, prometheus.GaugeValue, val)
if state == "scrubbing+deep" {
state = "deep_scrubbing"
}
ch <- prometheus.MustNewConstMetric(c.PGState, prometheus.GaugeValue, val, state) ch <- prometheus.MustNewConstMetric(c.PGState, prometheus.GaugeValue, val, state)
} }