From 9f472bd76feaebfe8a50f7ac3e9e05ce87ce3c6b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 2 Dec 2014 11:22:13 +0100 Subject: [PATCH] cpu plugin: Mark the "active" state as available. This fixes the !ByState && ByCpu case, i.e. when the user requests one metric ("active") per CPU. Bug: #820 --- src/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cpu.c b/src/cpu.c index 9d812c80..8d9c0a6f 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -419,6 +419,9 @@ static void aggregate (gauge_t *sum_by_state) /* {{{ */ RATE_ADD (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate, this_cpu_states[state].rate); } + if (!isnan (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate)) + this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].has_value = 1; + RATE_ADD (sum_by_state[COLLECTD_CPU_STATE_ACTIVE], this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate); } } /* }}} void aggregate */ @@ -514,7 +517,7 @@ static void cpu_commit (void) /* {{{ */ }; size_t state; - for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) + for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++) if (this_cpu_states[state].has_value) local_rates[state] = this_cpu_states[state].rate; -- 2.30.2