From f3c66dc0a4d5f80cd85289ab9847bf715bcb0aaf Mon Sep 17 00:00:00 2001 From: Eugenio Grosso Date: Tue, 22 Nov 2022 14:47:18 +0000 Subject: [PATCH] Fixed alerts collector --- internal/openmetrics-exporter/alerts_collector.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/openmetrics-exporter/alerts_collector.go b/internal/openmetrics-exporter/alerts_collector.go index c34a851..49f9b34 100644 --- a/internal/openmetrics-exporter/alerts_collector.go +++ b/internal/openmetrics-exporter/alerts_collector.go @@ -2,6 +2,9 @@ package collectors import ( + "fmt" + "strings" + "github.com/prometheus/client_golang/prometheus" "purestorage/fa-openmetrics-exporter/internal/rest-client" ) @@ -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], ) } }