in_node_exporter_metrics: handle missing fields in different kernel versions
#include <unistd.h>
+/*
+ * See kernel documentation for a description:
+ * https://www.kernel.org/doc/html/latest/filesystems/proc.html
+ *
+ * user: normal processes executing in user mode
+ * nice: niced processes executing in user mode
+ * system: processes executing in kernel mode
+ * idle: twiddling thumbs
+ * iowait: In a word, iowait stands for waiting for I/O to complete. But there are several problems:
+ * irq: servicing interrupts
+ * softirq: servicing softirqs
+ * steal: involuntary wait
+ * guest: running a normal guest
+ * guest_nice: running a niced guest
+ *
+ * Ensure to pick the correct version of the documentation, older versions here:
+ * https://github.com/torvalds/linux/tree/master/Documentation
+ */
struct cpu_stat_info {
double user;
double nice;
@@ -109,7 +127,7 @@ static int cpu_thermal_update(struct flb_ne *ctx, uint64_t ts)
continue;
}
- /* Phisical ID */
+ /* Physical ID */
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
entry->str,
"topology", "physical_package_id",
@@ -223,9 +241,15 @@ static int stat_line(char *line, struct cpu_stat_info *st)
&st->steal,
&st->guest,
&st->guest_nice);
- if (ret != 10) {
+
+ /* On some older kernels the 'guest_nice' value may be missing */
+ if (ret < 9) {
return -1;
}
+ /* Ensure we zero initialise it */
+ if ( ret == 9 ) {
+ st->guest_nice = 0;
+ }
/* Convert to seconds based on USER_HZ kernel param */
st->user /= user_hz;
