diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2026-05-19 09:18:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-19 09:18:20 +0200 |
| commit | 5ccce854954e807e51966b3db9388bf20284b949 (patch) | |
| tree | fda9a8073aa2403828884c5cfc2d517ea309df85 /plugins | |
| parent | 1211edf2eaee9b26eca0505d0708629548e29f6e (diff) | |
| download | monitoring-plugins-5ccce854954e807e51966b3db9388bf20284b949.tar.gz | |
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@netways.de>
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_load.c | 16 |
1 files changed, 6 insertions, 10 deletions
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 { | |||
| 65 | int errorcode; | 65 | int errorcode; |
| 66 | char **top_processes; | 66 | char **top_processes; |
| 67 | } top_processes_result; | 67 | } top_processes_result; |
| 68 | static top_processes_result print_top_consuming_processes(unsigned long n_procs_to_show); | 68 | static top_processes_result get_top_consuming_processes(unsigned long n_procs_to_show); |
| 69 | 69 | ||
| 70 | typedef struct { | 70 | typedef struct { |
| 71 | mp_range load[3]; | 71 | mp_range load[3]; |
| @@ -158,7 +158,7 @@ int main(int argc, char **argv) { | |||
| 158 | 158 | ||
| 159 | mp_subcheck scaled_load_sc = mp_subcheck_init(); | 159 | mp_subcheck scaled_load_sc = mp_subcheck_init(); |
| 160 | scaled_load_sc = mp_set_subcheck_default_state(scaled_load_sc, STATE_OK); | 160 | scaled_load_sc = mp_set_subcheck_default_state(scaled_load_sc, STATE_OK); |
| 161 | scaled_load_sc.output = "Scaled Load (divided by number of CPUs"; | 161 | scaled_load_sc.output = "Scaled Load (divided by number of CPUs)"; |
| 162 | 162 | ||
| 163 | mp_perfdata pd_scaled_load1 = perfdata_init(); | 163 | mp_perfdata pd_scaled_load1 = perfdata_init(); |
| 164 | pd_scaled_load1.label = "scaled_load1"; | 164 | pd_scaled_load1.label = "scaled_load1"; |
| @@ -248,12 +248,13 @@ int main(int argc, char **argv) { | |||
| 248 | if (config.n_procs_to_show > 0) { | 248 | if (config.n_procs_to_show > 0) { |
| 249 | mp_subcheck top_proc_sc = mp_subcheck_init(); | 249 | mp_subcheck top_proc_sc = mp_subcheck_init(); |
| 250 | top_proc_sc = mp_set_subcheck_state(top_proc_sc, STATE_OK); | 250 | top_proc_sc = mp_set_subcheck_state(top_proc_sc, STATE_OK); |
| 251 | top_processes_result top_proc = print_top_consuming_processes(config.n_procs_to_show); | 251 | top_processes_result top_proc = get_top_consuming_processes(config.n_procs_to_show); |
| 252 | xasprintf(&top_proc_sc.output, "Top %lu CPU time consuming processes", | 252 | xasprintf(&top_proc_sc.output, "Top %lu CPU time consuming processes", |
| 253 | config.n_procs_to_show); | 253 | config.n_procs_to_show); |
| 254 | 254 | ||
| 255 | if (top_proc.errorcode == OK) { | 255 | if (top_proc.errorcode == OK) { |
| 256 | for (unsigned long i = 0; i < config.n_procs_to_show; i++) { | 256 | // +1 here since the string list contains the header line |
| 257 | for (unsigned long i = 0; i < config.n_procs_to_show +1; i++) { | ||
| 257 | xasprintf(&top_proc_sc.output, "%s\n%s", top_proc_sc.output, | 258 | xasprintf(&top_proc_sc.output, "%s\n%s", top_proc_sc.output, |
| 258 | top_proc.top_processes[i]); | 259 | top_proc.top_processes[i]); |
| 259 | } | 260 | } |
| @@ -286,11 +287,6 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) { | |||
| 286 | .config = check_load_config_init(), | 287 | .config = check_load_config_init(), |
| 287 | }; | 288 | }; |
| 288 | 289 | ||
| 289 | if (argc < 2) { | ||
| 290 | result.errorcode = ERROR; | ||
| 291 | return result; | ||
| 292 | } | ||
| 293 | |||
| 294 | while (true) { | 290 | while (true) { |
| 295 | int option = 0; | 291 | int option = 0; |
| 296 | int option_index = getopt_long(argc, argv, "Vhrc:w:n:", longopts, &option); | 292 | int option_index = getopt_long(argc, argv, "Vhrc:w:n:", longopts, &option); |
| @@ -448,7 +444,7 @@ int cmpstringp(const void *p1, const void *p2) { | |||
| 448 | } | 444 | } |
| 449 | #endif /* PS_USES_PROCPCPU */ | 445 | #endif /* PS_USES_PROCPCPU */ |
| 450 | 446 | ||
| 451 | static top_processes_result print_top_consuming_processes(unsigned long n_procs_to_show) { | 447 | static top_processes_result get_top_consuming_processes(unsigned long n_procs_to_show) { |
| 452 | top_processes_result result = { | 448 | top_processes_result result = { |
| 453 | .errorcode = OK, | 449 | .errorcode = OK, |
| 454 | }; | 450 | }; |
