diff options
author | Marc Sánchez <sanchezfauste@gmail.com> | 2017-09-07 22:25:09 +0200 |
---|---|---|
committer | Marc Sánchez <sanchezfauste@gmail.com> | 2017-09-07 22:25:09 +0200 |
commit | c03e1ad081bc080cb8085bc14a94e4965a8e119e (patch) | |
tree | 23770f58a0b8b55604367a923ab081e259246472 | |
parent | 015a40e1b590bb847328d51bdfc4b544ae8825d3 (diff) | |
download | monitoring-plugins-c03e1ad.tar.gz |
Only turn on ordering procs by CPU usage if PS_USES_PROCPCPU
Disable sorting of procs by CPU usage on check_load if procpcpu is not present on PS_VARLIST
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | plugins/check_load.c | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index bf129956..08a0e782 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1016,6 +1016,10 @@ if test -n "$ac_cv_ps_varlist" ; then | |||
1016 | AC_DEFINE(PS_USES_PROCETIME,"yes", | 1016 | AC_DEFINE(PS_USES_PROCETIME,"yes", |
1017 | [Whether the ps utility uses the "procetime" field]) | 1017 | [Whether the ps utility uses the "procetime" field]) |
1018 | fi | 1018 | fi |
1019 | if echo "$ac_cv_ps_varlist" | grep "procpcpu" >/dev/null; then | ||
1020 | AC_DEFINE(PS_USES_PROCPCPU,"yes", | ||
1021 | [Whether the ps utility uses the "procpcpu" field]) | ||
1022 | fi | ||
1019 | fi | 1023 | fi |
1020 | 1024 | ||
1021 | AC_PATH_PROG(PATH_TO_PING,ping) | 1025 | AC_PATH_PROG(PATH_TO_PING,ping) |
diff --git a/plugins/check_load.c b/plugins/check_load.c index 6fd895f2..bf7b94b4 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -349,6 +349,7 @@ print_usage (void) | |||
349 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); | 349 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); |
350 | } | 350 | } |
351 | 351 | ||
352 | #ifdef PS_USES_PROCPCPU | ||
352 | int cmpstringp(const void *p1, const void *p2) { | 353 | int cmpstringp(const void *p1, const void *p2) { |
353 | int procuid = 0; | 354 | int procuid = 0; |
354 | int procpid = 0; | 355 | int procpid = 0; |
@@ -367,6 +368,7 @@ int cmpstringp(const void *p1, const void *p2) { | |||
367 | sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST); | 368 | sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST); |
368 | return procpcpu1 < procpcpu; | 369 | return procpcpu1 < procpcpu; |
369 | } | 370 | } |
371 | #endif /* PS_USES_PROCPCPU */ | ||
370 | 372 | ||
371 | static int print_top_consuming_processes() { | 373 | static int print_top_consuming_processes() { |
372 | int i = 0; | 374 | int i = 0; |
@@ -379,7 +381,9 @@ static int print_top_consuming_processes() { | |||
379 | fprintf(stderr, _("some error occurred getting procs list.\n")); | 381 | fprintf(stderr, _("some error occurred getting procs list.\n")); |
380 | return STATE_UNKNOWN; | 382 | return STATE_UNKNOWN; |
381 | } | 383 | } |
384 | #ifdef PS_USES_PROCPCPU | ||
382 | qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); | 385 | qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); |
386 | #endif /* PS_USES_PROCPCPU */ | ||
383 | int lines_to_show = chld_out.lines < (n_procs_to_show + 1) | 387 | int lines_to_show = chld_out.lines < (n_procs_to_show + 1) |
384 | ? chld_out.lines : n_procs_to_show + 1; | 388 | ? chld_out.lines : n_procs_to_show + 1; |
385 | for (i = 0; i < lines_to_show; i += 1) { | 389 | for (i = 0; i < lines_to_show; i += 1) { |