diff options
author | Marc Sánchez <sanchezfauste@gmail.com> | 2017-09-07 18:55:34 (GMT) |
---|---|---|
committer | Marc Sánchez <sanchezfauste@gmail.com> | 2017-09-07 18:55:34 (GMT) |
commit | 015a40e1b590bb847328d51bdfc4b544ae8825d3 (patch) | |
tree | a774a1d6c8e7a6aeb361584e71d71367832a1fd3 /plugins/check_load.c | |
parent | 0625fbb53db9401bdce95b1a403a20980a326ec4 (diff) | |
download | monitoring-plugins-015a40e1b590bb847328d51bdfc4b544ae8825d3.tar.gz |
Using PS_COMMAND constant and ordering output by procpcpu
Diffstat (limited to 'plugins/check_load.c')
-rw-r--r-- | plugins/check_load.c | 29 |
1 files 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) | |||
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 | int cmpstringp(const void *p1, const void *p2) { | ||
353 | int procuid = 0; | ||
354 | int procpid = 0; | ||
355 | int procppid = 0; | ||
356 | int procvsz = 0; | ||
357 | int procrss = 0; | ||
358 | float procpcpu = 0; | ||
359 | char procstat[8]; | ||
360 | #ifdef PS_USES_PROCETIME | ||
361 | char procetime[MAX_INPUT_BUFFER]; | ||
362 | #endif /* PS_USES_PROCETIME */ | ||
363 | char procprog[MAX_INPUT_BUFFER]; | ||
364 | int pos; | ||
365 | sscanf (* (char * const *) p1, PS_FORMAT, PS_VARLIST); | ||
366 | float procpcpu1 = procpcpu; | ||
367 | sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST); | ||
368 | return procpcpu1 < procpcpu; | ||
369 | } | ||
370 | |||
352 | static int print_top_consuming_processes() { | 371 | static int print_top_consuming_processes() { |
353 | int i = 0; | 372 | int i = 0; |
354 | struct output chld_out, chld_err; | 373 | struct output chld_out, chld_err; |
355 | char *cmdline = "/bin/ps -aux --sort=-pcpu"; | 374 | if(np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0) != 0){ |
356 | if(np_runcmd(cmdline, &chld_out, &chld_err, 0) != 0){ | 375 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), PS_COMMAND); |
357 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); | 376 | return STATE_UNKNOWN; |
377 | } | ||
378 | if (chld_out.lines < 2) { | ||
379 | fprintf(stderr, _("some error occurred getting procs list.\n")); | ||
358 | return STATE_UNKNOWN; | 380 | return STATE_UNKNOWN; |
359 | } | 381 | } |
382 | qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); | ||
360 | int lines_to_show = chld_out.lines < (n_procs_to_show + 1) | 383 | int lines_to_show = chld_out.lines < (n_procs_to_show + 1) |
361 | ? chld_out.lines : n_procs_to_show + 1; | 384 | ? chld_out.lines : n_procs_to_show + 1; |
362 | for (i = 0; i < lines_to_show; i += 1) { | 385 | for (i = 0; i < lines_to_show; i += 1) { |