Skip to content

Commit

Permalink
Fix pressure collector nil reference (prometheus#3016)
Browse files Browse the repository at this point in the history
Check that the PSI metrics are returned in order to avoid nil pointer
dereference.
* Update fixutre to match real-world samples.

Fixes: prometheus#3015

Signed-off-by: Ben Kochie <[email protected]>
  • Loading branch information
SuperQ committed May 21, 2024
1 parent e824cde commit 31e0145
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions collector/fixtures/proc/pressure/cpu
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions collector/pressure_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 31e0145

Please sign in to comment.