Skip to content

Commit 17e4c71

Browse files
committed
pressure: Fix missing IRQ on older kernels
Fix "no data" error on kernels that support some PSI status, but don't yet have IRQ presure metrics. Only report "no data" error if `pressure` is enabled and no PSI metrics were found. Fixes: prometheus#3259 Signed-off-by: Ben Kochie <[email protected]>
1 parent 0c10545 commit 17e4c71

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

collector/pressure_linux.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ import (
2727
"github.com/prometheus/procfs"
2828
)
2929

30+
const (
31+
psiResourceCPU = "cpu"
32+
psiResourceIO = "io"
33+
psiResourceMemory = "memory"
34+
psiResourceIRQ = "irq"
35+
)
36+
3037
var (
31-
psiResources = []string{"cpu", "io", "memory", "irq"}
38+
psiResources = []string{psiResourceCPU, psiResourceIO, psiResourceMemory, psiResourceIRQ}
3239
)
3340

3441
type pressureStatsCollector struct {
@@ -93,13 +100,18 @@ func NewPressureStatsCollector(logger *slog.Logger) (Collector, error) {
93100

94101
// Update calls procfs.NewPSIStatsForResource for the different resources and updates the values
95102
func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
103+
foundResources := 0
96104
for _, res := range psiResources {
97105
c.logger.Debug("collecting statistics for resource", "resource", res)
98106
vals, err := c.fs.PSIStatsForResource(res)
99107
if err != nil {
100-
if errors.Is(err, os.ErrNotExist) {
101-
c.logger.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel")
102-
return ErrNoData
108+
if errors.Is(err, os.ErrNotExist) && res != psiResourceIRQ {
109+
c.logger.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel", "resource", res)
110+
continue
111+
}
112+
if errors.Is(err, os.ErrNotExist) && res == psiResourceIRQ {
113+
c.logger.Debug("pressure information is unavailable, you need a Linux kernel >= 6.1 and/or CONFIG_PSI enabled for your kernel", "resource", res)
114+
continue
103115
}
104116
if errors.Is(err, syscall.ENOTSUP) {
105117
c.logger.Debug("pressure information is disabled, add psi=1 kernel command line to enable it")
@@ -130,7 +142,14 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
130142
ch <- prometheus.MustNewConstMetric(c.irqFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0)
131143
default:
132144
c.logger.Debug("did not account for resource", "resource", res)
145+
continue
133146
}
147+
foundResources++
148+
}
149+
150+
if foundResources == 0 {
151+
c.logger.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel")
152+
return ErrNoData
134153
}
135154

136155
return nil

0 commit comments

Comments
 (0)