@@ -27,8 +27,15 @@ import (
27
27
"github.com/prometheus/procfs"
28
28
)
29
29
30
+ const (
31
+ psiResourceCPU = "cpu"
32
+ psiResourceIO = "io"
33
+ psiResourceMemory = "memory"
34
+ psiResourceIRQ = "irq"
35
+ )
36
+
30
37
var (
31
- psiResources = []string {"cpu" , "io" , "memory" , "irq" }
38
+ psiResources = []string {psiResourceCPU , psiResourceIO , psiResourceMemory , psiResourceIRQ }
32
39
)
33
40
34
41
type pressureStatsCollector struct {
@@ -93,13 +100,18 @@ func NewPressureStatsCollector(logger *slog.Logger) (Collector, error) {
93
100
94
101
// Update calls procfs.NewPSIStatsForResource for the different resources and updates the values
95
102
func (c * pressureStatsCollector ) Update (ch chan <- prometheus.Metric ) error {
103
+ foundResources := 0
96
104
for _ , res := range psiResources {
97
105
c .logger .Debug ("collecting statistics for resource" , "resource" , res )
98
106
vals , err := c .fs .PSIStatsForResource (res )
99
107
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 ("IRQ pressure information is unavailable, you need a Linux kernel >= 6.1 and/or CONFIG_PSI enabled for your kernel" , "resource" , res )
114
+ continue
103
115
}
104
116
if errors .Is (err , syscall .ENOTSUP ) {
105
117
c .logger .Debug ("pressure information is disabled, add psi=1 kernel command line to enable it" )
@@ -109,28 +121,35 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
109
121
}
110
122
// IRQ pressure does not have 'some' data.
111
123
// See https://github.com/torvalds/linux/blob/v6.9/include/linux/psi_types.h#L65
112
- if vals .Some == nil && res != "irq" {
124
+ if vals .Some == nil && res != psiResourceIRQ {
113
125
c .logger .Debug ("pressure information returned no 'some' data" )
114
126
return ErrNoData
115
127
}
116
- if vals .Full == nil && res != "cpu" {
128
+ if vals .Full == nil && res != psiResourceCPU {
117
129
c .logger .Debug ("pressure information returned no 'full' data" )
118
130
return ErrNoData
119
131
}
120
132
switch res {
121
- case "cpu" :
133
+ case psiResourceCPU :
122
134
ch <- prometheus .MustNewConstMetric (c .cpu , prometheus .CounterValue , float64 (vals .Some .Total )/ 1000.0 / 1000.0 )
123
- case "io" :
135
+ case psiResourceIO :
124
136
ch <- prometheus .MustNewConstMetric (c .io , prometheus .CounterValue , float64 (vals .Some .Total )/ 1000.0 / 1000.0 )
125
137
ch <- prometheus .MustNewConstMetric (c .ioFull , prometheus .CounterValue , float64 (vals .Full .Total )/ 1000.0 / 1000.0 )
126
- case "memory" :
138
+ case psiResourceMemory :
127
139
ch <- prometheus .MustNewConstMetric (c .mem , prometheus .CounterValue , float64 (vals .Some .Total )/ 1000.0 / 1000.0 )
128
140
ch <- prometheus .MustNewConstMetric (c .memFull , prometheus .CounterValue , float64 (vals .Full .Total )/ 1000.0 / 1000.0 )
129
- case "irq" :
141
+ case psiResourceIRQ :
130
142
ch <- prometheus .MustNewConstMetric (c .irqFull , prometheus .CounterValue , float64 (vals .Full .Total )/ 1000.0 / 1000.0 )
131
143
default :
132
144
c .logger .Debug ("did not account for resource" , "resource" , res )
145
+ continue
133
146
}
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
134
153
}
135
154
136
155
return nil
0 commit comments