From: Florian Forster Date: Thu, 4 Jan 2024 16:58:52 +0000 (+0100) Subject: cpu plugin: Simplify the configuration options available. X-Git-Tag: 6.0.0-rc0~5^2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6867517d0dcd123157cd9852089daeaeecb9b9a;p=thirdparty%2Fcollectd.git cpu plugin: Simplify the configuration options available. * The options `ReportUsage`, `ReportUtilization`, and `ReportNumCpu` control which metrics are emitted on a high level. Other options no longer influence *what* is being collected. This also allows to report usage and utilization metrics simultaneously. * The documentation has been updated to reflect that the plugin no longer emits a percentage, but a ratio for utilization metrics. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 791236d04..18dd82ef6 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -417,9 +417,10 @@ # # +# ReportUsage true +# ReportUtilization true # ReportByCpu true # ReportByState true -# ValuesPercentage false # ReportNumCpu false # ReportGuestState false # SubtractGuestState true diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 2cf343c51..d0956097b 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1760,8 +1760,10 @@ F instead of F. =head2 Plugin C -The I collects CPU usage metrics. By default, CPU usage is reported -as Jiffies, using the C type. Two aggregations are available: +The I collects CPU usage and utilization metrics. +By default, both CPU usage and utilization are reported. + +For CPU utilization, two aggregations are available: =over 4 @@ -1776,34 +1778,38 @@ Sum, per-CPU, over all non-idle states of a CPU, creating an "active" state. =back The two aggregations can be combined, leading to I only emitting a -single "active" metric for the entire system. As soon as one of these -aggregations (or both) is enabled, the I 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 B|B + +Sets whether CPU usage (in jiffies/seconds) is reported. Defaults to B. + +=item B B|B + +Sets whether CPU utilization (a ratio) is reported. Defaults to B. + +When enabled, the B and B options can be used to +report aggregated data. + =item B B|B When set to B, the default, reports per-state metrics, e.g. "system", -"user" and "idle". -When set to B, aggregates (sums) all I states into one -"active" metric. +"user" and "idle". When set to B, aggregates (sums) all I +states into one "active" metric. -=item B B|B +This option only has an effect if B is true. -When set to B, the default, reports per-CPU (per-core) metrics. -When set to B, instead of reporting metrics for individual CPUs, only a -global sum of CPU states is emitted. +=item B B|B -=item B B|B +When set to B, the default, reports per-CPU (per-core) metrics. When set +to B, instead of reporting metrics for individual CPUs, only a global +sum of CPU states is emitted. -This option is only considered when both, B and B -are set to B. In this case, by default, metrics will be reported as -Jiffies. By setting this option to B, you can request percentage values -in the un-aggregated (per-CPU, per-state) mode as well. +This option only has an effect if B is true. =item B B|B diff --git a/src/cpu.c b/src/cpu.c index e85957747..c1b47836e 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -203,22 +203,28 @@ static size_t global_cpu_num; 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) @@ -518,7 +524,7 @@ static void cpu_reset(void) /* {{{ */ } /* }}} 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", @@ -552,23 +558,12 @@ static void cpu_commit_without_aggregation(void) /* {{{ */ 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]; @@ -590,6 +585,22 @@ static void cpu_commit(void) /* {{{ */ 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