[monitoring-plugins] Using PS_COMMAND constant and ordering output by ...
Marc Sánchez
git at monitoring-plugins.org
Thu Apr 4 13:10:16 CEST 2019
Module: monitoring-plugins
Branch: feature_check_curl
Commit: 015a40e1b590bb847328d51bdfc4b544ae8825d3
Author: Marc Sánchez <sanchezfauste at gmail.com>
Date: Thu Sep 7 20:55:34 2017 +0200
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=015a40e
Using PS_COMMAND constant and ordering output by procpcpu
---
plugins/check_load.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 5d5c115..6fd895f 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -349,14 +349,37 @@ print_usage (void)
printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname);
}
+int cmpstringp(const void *p1, const void *p2) {
+ int procuid = 0;
+ int procpid = 0;
+ int procppid = 0;
+ int procvsz = 0;
+ int procrss = 0;
+ float procpcpu = 0;
+ char procstat[8];
+#ifdef PS_USES_PROCETIME
+ char procetime[MAX_INPUT_BUFFER];
+#endif /* PS_USES_PROCETIME */
+ char procprog[MAX_INPUT_BUFFER];
+ int pos;
+ sscanf (* (char * const *) p1, PS_FORMAT, PS_VARLIST);
+ float procpcpu1 = procpcpu;
+ sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST);
+ return procpcpu1 < procpcpu;
+}
+
static int print_top_consuming_processes() {
int i = 0;
struct output chld_out, chld_err;
- char *cmdline = "/bin/ps -aux --sort=-pcpu";
- if(np_runcmd(cmdline, &chld_out, &chld_err, 0) != 0){
- fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline);
+ if(np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0) != 0){
+ fprintf(stderr, _("'%s' exited with non-zero status.\n"), PS_COMMAND);
+ return STATE_UNKNOWN;
+ }
+ if (chld_out.lines < 2) {
+ fprintf(stderr, _("some error occurred getting procs list.\n"));
return STATE_UNKNOWN;
}
+ qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp);
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