Skip to content

Commit 111f6e7

Browse files
author
Pat
authored
in_node_exporter_metrics: handle missing fields in different kernel versions (fluent#5833)
Signed-off-by: Patrick Stephens <[email protected]>
1 parent 892c17d commit 111f6e7

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

plugins/in_node_exporter_metrics/ne_cpu_linux.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@
2525

2626
#include <unistd.h>
2727

28+
/*
29+
* See kernel documentation for a description:
30+
* https://www.kernel.org/doc/html/latest/filesystems/proc.html
31+
*
32+
* user: normal processes executing in user mode
33+
* nice: niced processes executing in user mode
34+
* system: processes executing in kernel mode
35+
* idle: twiddling thumbs
36+
* iowait: In a word, iowait stands for waiting for I/O to complete. But there are several problems:
37+
* irq: servicing interrupts
38+
* softirq: servicing softirqs
39+
* steal: involuntary wait
40+
* guest: running a normal guest
41+
* guest_nice: running a niced guest
42+
*
43+
* Ensure to pick the correct version of the documentation, older versions here:
44+
* https://github.com/torvalds/linux/tree/master/Documentation
45+
*/
2846
struct cpu_stat_info {
2947
double user;
3048
double nice;
@@ -109,7 +127,7 @@ static int cpu_thermal_update(struct flb_ne *ctx, uint64_t ts)
109127
continue;
110128
}
111129

112-
/* Phisical ID */
130+
/* Physical ID */
113131
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
114132
entry->str,
115133
"topology", "physical_package_id",
@@ -223,9 +241,15 @@ static int stat_line(char *line, struct cpu_stat_info *st)
223241
&st->steal,
224242
&st->guest,
225243
&st->guest_nice);
226-
if (ret != 10) {
244+
245+
/* On some older kernels the 'guest_nice' value may be missing */
246+
if (ret < 9) {
227247
return -1;
228248
}
249+
/* Ensure we zero initialise it */
250+
if ( ret == 9 ) {
251+
st->guest_nice = 0;
252+
}
229253

230254
/* Convert to seconds based on USER_HZ kernel param */
231255
st->user /= user_hz;

0 commit comments

Comments
 (0)