@@ -45,13 +45,19 @@ var (
45
45
"CPU flags." ,
46
46
[]string {"cpu" , "flag" }, nil ,
47
47
)
48
+ nodeCPUContextSwitchDesc = prometheus .NewDesc (
49
+ prometheus .BuildFQName (namespace , cpuCollectorSubsystem , "context_switches_total" ),
50
+ "Number of context switches." ,
51
+ []string {"cpu" }, nil ,
52
+ )
48
53
)
49
54
50
55
type cpuCollector struct {
51
- cpu typedDesc
52
- cpuPhysical typedDesc
53
- cpuRunQueue typedDesc
54
- cpuFlags typedDesc
56
+ cpu typedDesc
57
+ cpuPhysical typedDesc
58
+ cpuRunQueue typedDesc
59
+ cpuFlags typedDesc
60
+ cpuContextSwitch typedDesc
55
61
56
62
logger * slog.Logger
57
63
tickPerSecond int64
@@ -75,12 +81,13 @@ func NewCpuCollector(logger *slog.Logger) (Collector, error) {
75
81
return nil , err
76
82
}
77
83
return & cpuCollector {
78
- cpu : typedDesc {nodeCPUSecondsDesc , prometheus .CounterValue },
79
- cpuPhysical : typedDesc {nodeCPUPhysicalSecondsDesc , prometheus .CounterValue },
80
- cpuRunQueue : typedDesc {nodeCPUSRunQueueDesc , prometheus .GaugeValue },
81
- cpuFlags : typedDesc {nodeCPUFlagsDesc , prometheus .GaugeValue },
82
- logger : logger ,
83
- tickPerSecond : ticks ,
84
+ cpu : typedDesc {nodeCPUSecondsDesc , prometheus .CounterValue },
85
+ cpuPhysical : typedDesc {nodeCPUPhysicalSecondsDesc , prometheus .CounterValue },
86
+ cpuRunQueue : typedDesc {nodeCPUSRunQueueDesc , prometheus .GaugeValue },
87
+ cpuFlags : typedDesc {nodeCPUFlagsDesc , prometheus .GaugeValue },
88
+ cpuContextSwitch : typedDesc {nodeCPUContextSwitchDesc , prometheus .CounterValue },
89
+ logger : logger ,
90
+ tickPerSecond : ticks ,
84
91
}, nil
85
92
}
86
93
@@ -108,6 +115,9 @@ func (c *cpuCollector) Update(ch chan<- prometheus.Metric) error {
108
115
109
116
// Flags
110
117
ch <- c .cpuFlags .mustNewConstMetric (float64 (stat .SpurrFlag ), strconv .Itoa (n ), "spurr" )
118
+
119
+ // Context switches
120
+ ch <- c .cpuContextSwitch .mustNewConstMetric (float64 (stat .CSwitches ), strconv .Itoa (n ))
111
121
}
112
122
return nil
113
123
}
0 commit comments