Fix/check load inconsistencies (#2267)
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Spellcheck / codespell (push) Waiting to run
Tests / Running unit and integrationt tests (push) Waiting to run
Tests / Running rpm build test on almalinux:9 (push) Waiting to run
Tests / Running rpm build test on fedora:latest (push) Waiting to run
Tests / Running rpm build test on rockylinux:8 (push) Waiting to run

* 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>
This commit is contained in:
Lorenz Kästle 2026-05-19 09:18:20 +02:00 committed by GitHub
parent 1211edf2ea
commit 5ccce85495
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 11 deletions

View file

@ -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;

View file

@ -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,
};