From 3afc0a341e3c2c6605b18a882fb045318c18c444 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Thu, 16 May 2024 08:38:58 +0200 Subject: [PATCH] Fix pressure collector nil reference (#3016) Check that the PSI metrics are returned in order to avoid nil pointer dereference. * Update fixutre to match real-world samples. Fixes: https://github.com/prometheus/node_exporter/issues/3015 Signed-off-by: Ben Kochie --- collector/fixtures/proc/pressure/cpu | 1 + collector/pressure_linux.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/collector/fixtures/proc/pressure/cpu b/collector/fixtures/proc/pressure/cpu index 14acc3a3..0aaced93 100644 --- a/collector/fixtures/proc/pressure/cpu +++ b/collector/fixtures/proc/pressure/cpu @@ -1 +1,2 @@ some avg10=0.00 avg60=0.00 avg300=0.00 total=14036781 +full avg10=0.00 avg60=0.00 avg300=0.00 total=0 diff --git a/collector/pressure_linux.go b/collector/pressure_linux.go index ceaced7e..4dbdc539 100644 --- a/collector/pressure_linux.go +++ b/collector/pressure_linux.go @@ -102,6 +102,14 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { } return fmt.Errorf("failed to retrieve pressure stats: %w", err) } + if vals.Some == nil { + level.Debug(c.logger).Log("msg", "pressure information returned no 'some' data") + return ErrNoData + } + if vals.Full == nil { + level.Debug(c.logger).Log("msg", "pressure information returned no 'full' data") + return ErrNoData + } switch res { case "cpu": ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)