From d6e64a1a4e66562e4ad61564294db64505e5c38d Mon Sep 17 00:00:00 2001 From: Lukas Schlacher Date: Mon, 19 Aug 2024 16:58:10 +0200 Subject: [PATCH] rasdaemon: fix metrics --- BUILD.bazel | 2 +- rasdaemon.go | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 030cff1..c789abf 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -126,6 +126,6 @@ pkg_deb( "repo:dpkg-bullseye", "repo:dpkg-buster", ], - version = "1.9.4", + version = "1.10.0", visibility = ["//visibility:public"], ) diff --git a/rasdaemon.go b/rasdaemon.go index 190ef0b..55b3a99 100644 --- a/rasdaemon.go +++ b/rasdaemon.go @@ -66,7 +66,13 @@ func (c *RasdaemonChecker) Describe(ch chan<- *prometheus.Desc) { } func (c *RasdaemonChecker) CollectRasdaemonMCERecordSize(ch chan<- prometheus.Metric) { - rows, err := c.db.Query("select bank, bank_name, error_msg, count(id) from mce_record group by bank, bank_name, error_msg") + //nolint:godox + // Todo: This could break when rasdaemon is updated. + // See: https://pagure.io/rasdaemon/blob/master/f/mce-amd.c + rows, err := c.db.Query(` + select bank, bank_name, (case when error_msg like '% no action required.' then 'no' else 'yes' end) as action_required, count(id) + from mce_record group by bank, bank_name, action_required; + `) if err != nil { log.Println("failed to query mce_record:", err) return @@ -76,38 +82,22 @@ func (c *RasdaemonChecker) CollectRasdaemonMCERecordSize(ch chan<- prometheus.Me var size int var bank int var bankName string - var errorMsg string + var actionRequired string - if err := rows.Scan(&bank, &bankName, &errorMsg, &size); err != nil { + if err := rows.Scan(&bank, &bankName, &actionRequired, &size); err != nil { log.Println("sql.Scan:", err) continue } // Trim unnecessary mentioning of bank in bank_name - example: bank = 18, bank_name = Unified Memory Controller (bank=18) bankName = strings.TrimSuffix(bankName, fmt.Sprintf(" (bank=%d)", bank)) - - //nolint:godox - // Todo: This could break when rasdaemon is updated. - // See: https://pagure.io/rasdaemon/blob/master/f/mce-amd.c - if strings.HasSuffix(errorMsg, " no action required.") { - ch <- prometheus.MustNewConstMetric( - c.promRasdaemonMCERecordSize, - prometheus.GaugeValue, - float64(size), - strconv.Itoa(bank), - bankName, - "no", - ) - continue - } - ch <- prometheus.MustNewConstMetric( c.promRasdaemonMCERecordSize, prometheus.GaugeValue, float64(size), strconv.Itoa(bank), bankName, - "yes", + actionRequired, ) } if err := rows.Err(); err != nil {