[monitoring-plugins] Only turn on ordering procs by CPU usage if ...
Marc Sánchez
git at monitoring-plugins.org
Thu Apr 4 13:10:16 CEST 2019
Module: monitoring-plugins
Branch: feature_check_curl
Commit: c03e1ad081bc080cb8085bc14a94e4965a8e119e
Author: Marc Sánchez <sanchezfauste at gmail.com>
Date: Thu Sep 7 22:25:09 2017 +0200
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=c03e1ad
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
---
configure.ac | 4 ++++
plugins/check_load.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/configure.ac b/configure.ac
index bf12995..08a0e78 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1016,6 +1016,10 @@ if test -n "$ac_cv_ps_varlist" ; then
AC_DEFINE(PS_USES_PROCETIME,"yes",
[Whether the ps utility uses the "procetime" field])
fi
+ if echo "$ac_cv_ps_varlist" | grep "procpcpu" >/dev/null; then
+ AC_DEFINE(PS_USES_PROCPCPU,"yes",
+ [Whether the ps utility uses the "procpcpu" field])
+ fi
fi
AC_PATH_PROG(PATH_TO_PING,ping)
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 6fd895f..bf7b94b 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -349,6 +349,7 @@ print_usage (void)
printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname);
}
+#ifdef PS_USES_PROCPCPU
int cmpstringp(const void *p1, const void *p2) {
int procuid = 0;
int procpid = 0;
@@ -367,6 +368,7 @@ int cmpstringp(const void *p1, const void *p2) {
sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST);
return procpcpu1 < procpcpu;
}
+#endif /* PS_USES_PROCPCPU */
static int print_top_consuming_processes() {
int i = 0;
@@ -379,7 +381,9 @@ static int print_top_consuming_processes() {
fprintf(stderr, _("some error occurred getting procs list.\n"));
return STATE_UNKNOWN;
}
+#ifdef PS_USES_PROCPCPU
qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp);
+#endif /* PS_USES_PROCPCPU */
int lines_to_show = chld_out.lines < (n_procs_to_show + 1)
? chld_out.lines : n_procs_to_show + 1;
for (i = 0; i < lines_to_show; i += 1) {
More information about the Commits
mailing list