From: Florian Forster Date: Tue, 9 Jan 2024 12:07:08 +0000 (+0100) Subject: cpu plugin: Skip states that don't have any data. X-Git-Tag: 6.0.0-rc0~5^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d1c86b6117377fe6c9384517dec88d075525e59;p=thirdparty%2Fcollectd.git cpu plugin: Skip states that don't have any data. --- diff --git a/src/cpu.c b/src/cpu.c index 23ef10ca5..4e98481e1 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -630,6 +630,9 @@ static void commit_cpu_usage(usage_t *u, size_t cpu_num) { if (report_by_state) { for (state_t state = 0; state < STATE_ACTIVE; state++) { derive_t usage = usage_count(u, cpu_num, state); + if (usage == -1) { + continue; + } metric_family_append(&fam, label_state, cpu_state_names[state], (value_t){.derive = usage}, &m); } @@ -689,6 +692,9 @@ static void commit_cpu_utilization(usage_t *u, size_t cpu_num) { } else { for (state_t state = 0; state < STATE_ACTIVE; state++) { gauge_t ratio = usage_ratio(u, cpu_num, state); + if (isnan(ratio)) { + continue; + } metric_family_append(&fam, label_state, cpu_state_names[state], (value_t){.gauge = ratio}, &m); }