Skip to content

Commit

Permalink
Fix pressure collector nil reference
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: #3015

Signed-off-by: Ben Kochie <superq@gmail.com>
  • Loading branch information
SuperQ committed May 14, 2024
1 parent 2ecbe97 commit b12ab35
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
@@ -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
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 b12ab35

Please sign in to comment.