[monitoring-plugins] Fix/check load inconsistencies (#2267)
GitHub
git at monitoring-plugins.org
Tue May 19 09:20:13 CEST 2026
Module: monitoring-plugins
Branch: master
Commit: 5ccce854954e807e51966b3db9388bf20284b949
Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
Committer: GitHub <noreply at github.com>
Date: Tue May 19 09:18:20 2026 +0200
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=5ccce854
Fix/check load inconsistencies (#2267)
* Remove redundant new line in multi-line outputs
* check_load: Fix missing brace in output
* check_load: rename function to properly indicate purpose
* check_load: show the correct amount of procs
* check_load: allow execution without parameters
---------
Co-authored-by: Lorenz Kästle <lorenz.kaestle at netways.de>
---
lib/output.c | 2 +-
plugins/check_load.c | 16 ++++++----------
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/lib/output.c b/lib/output.c
index 54d505d9..3c04d63d 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -420,7 +420,7 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
// add the rest (if any)
if (have_residual_chars) {
char *tmp = check.output;
- xasprintf(&check.output, "%s\n%s%s", intermediate_string,
+ xasprintf(&check.output, "%s%s%s", intermediate_string,
generate_indentation_string(indentation + 1), tmp);
} else {
check.output = intermediate_string;
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 60fa646f..7995408e 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -65,7 +65,7 @@ typedef struct {
int errorcode;
char **top_processes;
} top_processes_result;
-static top_processes_result print_top_consuming_processes(unsigned long n_procs_to_show);
+static top_processes_result get_top_consuming_processes(unsigned long n_procs_to_show);
typedef struct {
mp_range load[3];
@@ -158,7 +158,7 @@ int main(int argc, char **argv) {
mp_subcheck scaled_load_sc = mp_subcheck_init();
scaled_load_sc = mp_set_subcheck_default_state(scaled_load_sc, STATE_OK);
- scaled_load_sc.output = "Scaled Load (divided by number of CPUs";
+ scaled_load_sc.output = "Scaled Load (divided by number of CPUs)";
mp_perfdata pd_scaled_load1 = perfdata_init();
pd_scaled_load1.label = "scaled_load1";
@@ -248,12 +248,13 @@ int main(int argc, char **argv) {
if (config.n_procs_to_show > 0) {
mp_subcheck top_proc_sc = mp_subcheck_init();
top_proc_sc = mp_set_subcheck_state(top_proc_sc, STATE_OK);
- top_processes_result top_proc = print_top_consuming_processes(config.n_procs_to_show);
+ top_processes_result top_proc = get_top_consuming_processes(config.n_procs_to_show);
xasprintf(&top_proc_sc.output, "Top %lu CPU time consuming processes",
config.n_procs_to_show);
if (top_proc.errorcode == OK) {
- for (unsigned long i = 0; i < config.n_procs_to_show; i++) {
+ // +1 here since the string list contains the header line
+ for (unsigned long i = 0; i < config.n_procs_to_show +1; i++) {
xasprintf(&top_proc_sc.output, "%s\n%s", top_proc_sc.output,
top_proc.top_processes[i]);
}
@@ -286,11 +287,6 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
.config = check_load_config_init(),
};
- if (argc < 2) {
- result.errorcode = ERROR;
- return result;
- }
-
while (true) {
int option = 0;
int option_index = getopt_long(argc, argv, "Vhrc:w:n:", longopts, &option);
@@ -448,7 +444,7 @@ int cmpstringp(const void *p1, const void *p2) {
}
#endif /* PS_USES_PROCPCPU */
-static top_processes_result print_top_consuming_processes(unsigned long n_procs_to_show) {
+static top_processes_result get_top_consuming_processes(unsigned long n_procs_to_show) {
top_processes_result result = {
.errorcode = OK,
};
More information about the Commits
mailing list