=head2 Plugin C<cpu>
-The I<CPU plugin> collects CPU usage metrics. By default, CPU usage is reported
-as Jiffies, using the C<cpu> type. Two aggregations are available:
+The I<CPU plugin> collects CPU usage and utilization metrics.
+By default, both CPU usage and utilization are reported.
+
+For CPU utilization, two aggregations are available:
=over 4
=back
The two aggregations can be combined, leading to I<collectd> only emitting a
-single "active" metric for the entire system. As soon as one of these
-aggregations (or both) is enabled, the I<cpu plugin> will report a percentage,
-rather than Jiffies. In addition, you can request individual, per-state,
-per-CPU metrics to be reported as percentage.
+single "active" metric for the entire system.
The following configuration options are available:
=over 4
+=item B<ReportUsage> B<true>|B<false>
+
+Sets whether CPU usage (in jiffies/seconds) is reported. Defaults to B<true>.
+
+=item B<ReportUtilization> B<true>|B<false>
+
+Sets whether CPU utilization (a ratio) is reported. Defaults to B<true>.
+
+When enabled, the B<ReportByState> and B<ReportByCpu> options can be used to
+report aggregated data.
+
=item B<ReportByState> B<true>|B<false>
When set to B<true>, the default, reports per-state metrics, e.g. "system",
-"user" and "idle".
-When set to B<false>, aggregates (sums) all I<non-idle> states into one
-"active" metric.
+"user" and "idle". When set to B<false>, aggregates (sums) all I<non-idle>
+states into one "active" metric.
-=item B<ReportByCpu> B<true>|B<false>
+This option only has an effect if B<ReportUtilization> is true.
-When set to B<true>, the default, reports per-CPU (per-core) metrics.
-When set to B<false>, instead of reporting metrics for individual CPUs, only a
-global sum of CPU states is emitted.
+=item B<ReportByCpu> B<true>|B<false>
-=item B<ValuesPercentage> B<false>|B<true>
+When set to B<true>, the default, reports per-CPU (per-core) metrics. When set
+to B<false>, instead of reporting metrics for individual CPUs, only a global
+sum of CPU states is emitted.
-This option is only considered when both, B<ReportByCpu> and B<ReportByState>
-are set to B<true>. In this case, by default, metrics will be reported as
-Jiffies. By setting this option to B<true>, you can request percentage values
-in the un-aggregated (per-CPU, per-state) mode as well.
+This option only has an effect if B<ReportUtilization> is true.
=item B<ReportNumCpu> B<false>|B<true>
static bool report_by_cpu = true;
static bool report_by_state = true;
-static bool report_percent;
+static bool report_usage = true;
+static bool report_utilization = true;
static bool report_num_cpu;
static bool report_guest;
static bool subtract_guest = true;
-static const char *config_keys[] = {"ReportByCpu", "ReportByState",
- "ReportNumCpu", "ValuesPercentage",
- "ReportGuestState", "SubtractGuestState"};
+static const char *config_keys[] = {
+ "ReportByCpu", "ReportByState", "ReportNumCpu",
+ "ReportUtilization", "ValuesPercentage", "ReportGuestState",
+ "SubtractGuestState",
+};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
static int cpu_config(char const *key, char const *value) /* {{{ */
{
if (strcasecmp(key, "ReportByCpu") == 0)
report_by_cpu = IS_TRUE(value);
- else if (strcasecmp(key, "ValuesPercentage") == 0)
- report_percent = IS_TRUE(value);
+ else if (strcasecmp(key, "ReportUsage") == 0)
+ report_usage = IS_TRUE(value);
+ else if (strcasecmp(key, "ReportUtilization") == 0 ||
+ strcasecmp(key, "ValuesPercentage") == 0)
+ report_utilization = IS_TRUE(value);
else if (strcasecmp(key, "ReportByState") == 0)
report_by_state = IS_TRUE(value);
else if (strcasecmp(key, "ReportNumCpu") == 0)
} /* }}} void cpu_reset */
/* Legacy behavior: Dispatches the raw derive values without any aggregation. */
-static void cpu_commit_without_aggregation(void) /* {{{ */
+static void cpu_commit_usage(void) /* {{{ */
{
metric_family_t fam = {
.name = "system.cpu.time",
metric_reset(&m);
metric_family_metric_reset(&fam);
-} /* }}} void cpu_commit_without_aggregation */
+} /* }}} void cpu_commit_usage */
-/* Aggregates the internal state and dispatches the metrics. */
-static void cpu_commit(void) /* {{{ */
-{
+static void cpu_commit_utilization(void) {
gauge_t global_rates[STATE_MAX] = {
NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN /* Batman! */
};
-
- if (report_num_cpu)
- cpu_commit_num_cpu((gauge_t)global_cpu_num);
-
- if (report_by_state && report_by_cpu && !report_percent) {
- cpu_commit_without_aggregation();
- return;
- }
-
aggregate(global_rates);
gauge_t global_rate_sum = global_rates[STATE_ACTIVE];
cpu_commit_one((int)cpu_num, local_rates, global_rate_sum);
}
+}
+
+/* Aggregates the internal state and dispatches the metrics. */
+static void cpu_commit(void) /* {{{ */
+{
+ if (report_num_cpu) {
+ cpu_commit_num_cpu((gauge_t)global_cpu_num);
+ }
+
+ if (report_usage) {
+ cpu_commit_usage();
+ }
+
+ if (report_utilization) {
+ cpu_commit_utilization();
+ }
} /* }}} void cpu_commit */
/* Adds a derive value to the internal state. This should be used by each read