Code

cpu plugin: Mark the "active" state as available.
authorFlorian Forster <octo@collectd.org>
Tue, 2 Dec 2014 10:22:13 +0000 (11:22 +0100)
committerFlorian Forster <octo@collectd.org>
Tue, 2 Dec 2014 10:22:13 +0000 (11:22 +0100)
This fixes the !ByState && ByCpu case, i.e. when the user requests one
metric ("active") per CPU.

Bug: #820

src/cpu.c

index 9d812c803bb1505a20e295d42c0ad3760426c8db..8d9c0a6f06388c77b807bd12b5ccf0d81a7e856e 100644 (file)
--- 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;