cpu plugin: Don't report empty cpu states.
authorFlorian Forster <octo@collectd.org>
Fri, 26 Sep 2014 02:10:32 +0000 (19:10 -0700)
committerFlorian Forster <octo@collectd.org>
Fri, 26 Sep 2014 02:10:32 +0000 (19:10 -0700)
src/cpu.c

index 475d18a..fae7ab9 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -343,6 +343,12 @@ static void submit_percent(int cpu_num, int cpu_state, gauge_t percent)
 {
        value_t value;
 
+       /* This function is called for all known CPU states, but each read
+        * method will only report a subset. The remaining states are left as
+        * NAN and we ignore them here. */
+       if (isnan (percent))
+               return;
+
        value.gauge = percent;
        submit_value (cpu_num, cpu_state, "percent", value);
 }
@@ -362,9 +368,6 @@ static int cpu_states_alloc (size_t cpu_num) /* {{{ */
        cpu_state_t *tmp;
        size_t sz;
 
-       if (cpu_num < 0)
-               return (EINVAL);
-
        sz = (((size_t) cpu_num) + 1) * CPU_STATE_MAX;
        assert (sz > 0);