allow for 'ReportByCpu false' and 'ValuesPercentage false'
[collectd.git] / src / cpu.c
index fae7ab9..91dfade 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -472,13 +472,13 @@ static void cpu_reset (void) /* {{{ */
 /* Legacy behavior: Dispatches the raw derive values without any aggregation. */
 static void cpu_commit_without_aggregation (void) /* {{{ */
 {
-       size_t cpu_num;
+       int state;
 
-       for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+       for (state = 0; state < CPU_STATE_ACTIVE; state++)
        {
-               int state;
-
-               for (state = 0; state < CPU_STATE_ACTIVE; state++)
+               size_t cpu_num;
+               if (report_by_cpu) {
+               for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
                {
                        cpu_state_t *s = get_cpu_state (cpu_num, state);
 
@@ -487,6 +487,20 @@ static void cpu_commit_without_aggregation (void) /* {{{ */
 
                        submit_derive ((int) cpu_num, (int) state, s->conv.last_value.derive);
                }
+               } else {
+               derive_t derive_total = 0;
+               for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+               {
+                       cpu_state_t *s = get_cpu_state (cpu_num, state);
+
+                       if (!s->has_value)
+                               continue;
+
+                       derive_total += s->conv.last_value.derive;
+                       
+               }
+               submit_derive (-1, (int) state, derive_total);
+               }
        }
 } /* }}} void cpu_commit_without_aggregation */
 
@@ -498,7 +512,7 @@ static void cpu_commit (void) /* {{{ */
        };
        size_t cpu_num;
 
-       if (report_by_cpu && report_by_state && !report_percent)
+       if (report_by_state && !report_percent)
        {
                cpu_commit_without_aggregation ();
                return;
@@ -772,11 +786,11 @@ static int cpu_read (void)
        }
 
        for (i = 0; i < numcpu; i++) {
-               cpu_state (i, CPU_STATE_USER,      (derive_t) cpuinfo[i][CP_USER]);
-               cpu_state (i, CPU_STATE_NICE,      (derive_t) cpuinfo[i][CP_NICE]);
-               cpu_state (i, CPU_STATE_SYSTEM,    (derive_t) cpuinfo[i][CP_SYS]);
-               cpu_state (i, CPU_STATE_IDLE,      (derive_t) cpuinfo[i][CP_IDLE]);
-               cpu_state (i, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR]);
+               cpu_stage (i, CPU_STATE_USER,      (derive_t) cpuinfo[i][CP_USER], now);
+               cpu_stage (i, CPU_STATE_NICE,      (derive_t) cpuinfo[i][CP_NICE], now);
+               cpu_stage (i, CPU_STATE_SYSTEM,    (derive_t) cpuinfo[i][CP_SYS], now);
+               cpu_stage (i, CPU_STATE_IDLE,      (derive_t) cpuinfo[i][CP_IDLE], now);
+               cpu_stage (i, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
        }
 /* }}} #endif CAN_USE_SYSCTL */
 
@@ -797,11 +811,11 @@ static int cpu_read (void)
        }
 
        for (i = 0; i < numcpu; i++) {
-               cpu_state (i, CPU_STATE_USER,      (derive_t) cpuinfo[i][CP_USER]);
-               cpu_state (i, CPU_STATE_NICE,      (derive_t) cpuinfo[i][CP_NICE]);
-               cpu_state (i, CPU_STATE_SYSTEM,    (derive_t) cpuinfo[i][CP_SYS]);
-               cpu_state (i, CPU_STATE_IDLE,      (derive_t) cpuinfo[i][CP_IDLE]);
-               cpu_state (i, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR]);
+               cpu_stage (i, CPU_STATE_USER,      (derive_t) cpuinfo[i][CP_USER], now);
+               cpu_stage (i, CPU_STATE_NICE,      (derive_t) cpuinfo[i][CP_NICE], now);
+               cpu_stage (i, CPU_STATE_SYSTEM,    (derive_t) cpuinfo[i][CP_SYS], now);
+               cpu_stage (i, CPU_STATE_IDLE,      (derive_t) cpuinfo[i][CP_IDLE], now);
+               cpu_stage (i, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
        }
 /* }}} #endif HAVE_SYSCTL_KERN_CP_TIMES */
 
@@ -819,11 +833,11 @@ static int cpu_read (void)
                return (-1);
        }
 
-       cpu_state (0, CPU_STATE_USER,      (derive_t) cpuinfo[CP_USER]);
-       cpu_state (0, CPU_STATE_NICE,      (derive_t) cpuinfo[CP_NICE]);
-       cpu_state (0, CPU_STATE_SYSTEM,    (derive_t) cpuinfo[CP_SYS]);
-       cpu_state (0, CPU_STATE_IDLE,      (derive_t) cpuinfo[CP_IDLE]);
-       cpu_state (0, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[CP_INTR]);
+       cpu_stage (0, CPU_STATE_USER,      (derive_t) cpuinfo[CP_USER], now);
+       cpu_stage (0, CPU_STATE_NICE,      (derive_t) cpuinfo[CP_NICE], now);
+       cpu_stage (0, CPU_STATE_SYSTEM,    (derive_t) cpuinfo[CP_SYS], now);
+       cpu_stage (0, CPU_STATE_IDLE,      (derive_t) cpuinfo[CP_IDLE], now);
+       cpu_stage (0, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[CP_INTR], now);
 /* }}} #endif HAVE_SYSCTLBYNAME */
 
 #elif defined(HAVE_LIBSTATGRAB) /* {{{ */