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.

Fixes: #3015

Signed-off-by: Ben Kochie <superq@gmail.com>
  • Loading branch information
SuperQ committed May 14, 2024
1 parent 2ecbe97 commit 058f817
Showing 1 changed file with 8 additions and 0 deletions.
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 058f817

Please sign in to comment.