Skip to content

Commit

Permalink
Fixed alerts collector
Browse files Browse the repository at this point in the history
  • Loading branch information
genegr committed Nov 22, 2022
1 parent 9246ca7 commit f3c66dc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/openmetrics-exporter/alerts_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package collectors


import (
"fmt"
"strings"

"github.com/prometheus/client_golang/prometheus"
"purestorage/fa-openmetrics-exporter/internal/rest-client"
)
Expand All @@ -20,12 +23,17 @@ func (c *AlertsCollector) Collect(ch chan<- prometheus.Metric) {
if len(alerts.Items) == 0 {
return
}
al := make(map[string]float64)
for _, alert := range alerts.Items {
al[fmt.Sprintf("%s,%s,%s", alert.Severity, alert.ComponentType, alert.ComponentName)] += 1
}
for a, n := range al {
alert := strings.Split(a, ",")
ch <- prometheus.MustNewConstMetric(
c.AlertsDesc,
prometheus.GaugeValue,
1.0,
alert.ComponentName, alert.ComponentType, alert.Severity,
n,
alert[0], alert[1], alert[2],
)
}
}
Expand Down

0 comments on commit f3c66dc

Please sign in to comment.