Skip to content

Commit

Permalink
Merge branch 'topic/rasdaemon' into 'master'
Browse files Browse the repository at this point in the history
rasdaemon: fix metrics

See merge request mgit/prometheus-mgit-exporter!19
  • Loading branch information
lschlacher committed Aug 20, 2024
2 parents 28e9b02 + d6e64a1 commit 2403fee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ pkg_deb(
"repo:dpkg-bullseye",
"repo:dpkg-buster",
],
version = "1.9.4",
version = "1.10.0",
visibility = ["//visibility:public"],
)
30 changes: 10 additions & 20 deletions rasdaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 2403fee

Please sign in to comment.