diff options
author | Matthew Kent <mattkent@users.sourceforge.net> | 2004-12-03 04:10:19 +0000 |
---|---|---|
committer | Matthew Kent <mattkent@users.sourceforge.net> | 2004-12-03 04:10:19 +0000 |
commit | f0336fc9accee63c1500ec735944d936259865ea (patch) | |
tree | 768eae4e149cb19c234ac6e9b31870a837d4a68f | |
parent | 06f6a8522704a5deabdc961d8db9e9462f34ea02 (diff) | |
download | monitoring-plugins-f0336fc9accee63c1500ec735944d936259865ea.tar.gz |
Patch from Russell Miller which adds elapsed time as a metric. Only for linux so far. (991359)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@984 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | configure.in | 12 | ||||
-rw-r--r-- | plugins/check_procs.c | 106 |
2 files changed, 101 insertions, 17 deletions
diff --git a/configure.in b/configure.in index 17bc5abb..d409b1c4 100644 --- a/configure.in +++ b/configure.in | |||
@@ -662,13 +662,13 @@ then | |||
662 | AC_MSG_RESULT([$ac_cv_ps_command]) | 662 | AC_MSG_RESULT([$ac_cv_ps_command]) |
663 | 663 | ||
664 | dnl STAT UCOMM VSZ RSS USER UID PPID COMMAND | 664 | dnl STAT UCOMM VSZ RSS USER UID PPID COMMAND |
665 | elif ps -weo 'stat comm vsz rss user uid ppid args' 2>/dev/null | \ | 665 | elif ps -weo 'stat comm vsz rss user uid ppid etime args' 2>/dev/null | \ |
666 | egrep -i ["^ *S[TAUES]* +[UCOMDNA]+ +[VSIZE]+ +R[S]+ +U[SER]+ +U[ID]+ +P[PID]+ +[RGSCOMDNA]+"] >/dev/null | 666 | egrep -i ["^ *S[TAUES]* +[UCOMDNA]+ +[VSIZE]+ +R[S]+ +U[SER]+ +U[ID]+ +P[PID]+ +[ELAPSD]+ +[RGSCOMDNA]+"] >/dev/null |
667 | then | 667 | then |
668 | ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" | 668 | ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]" |
669 | ac_cv_ps_command="$PATH_TO_PS -weo 'stat uid ppid vsz rss pcpu comm args'" | 669 | ac_cv_ps_command="$PATH_TO_PS -weo 'stat uid ppid vsz rss pcpu etime comm args'" |
670 | ac_cv_ps_format="%s %d %d %d %d %f %s %n" | 670 | ac_cv_ps_format="%s %d %d %d %d %f %s %s %n" |
671 | ac_cv_ps_cols=8 | 671 | ac_cv_ps_cols=9 |
672 | AC_MSG_RESULT([$ac_cv_ps_command]) | 672 | AC_MSG_RESULT([$ac_cv_ps_command]) |
673 | 673 | ||
674 | dnl FreeBSD | 674 | dnl FreeBSD |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 4d01a1c2..a8a7d5e8 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -32,6 +32,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
32 | int process_arguments (int, char **); | 32 | int process_arguments (int, char **); |
33 | int validate_arguments (void); | 33 | int validate_arguments (void); |
34 | int check_thresholds (int); | 34 | int check_thresholds (int); |
35 | int convert_to_seconds (char *); | ||
35 | void print_help (void); | 36 | void print_help (void); |
36 | void print_usage (void); | 37 | void print_usage (void); |
37 | 38 | ||
@@ -50,14 +51,15 @@ int options = 0; /* bitmask of filter criteria to test against */ | |||
50 | #define VSZ 64 | 51 | #define VSZ 64 |
51 | #define RSS 128 | 52 | #define RSS 128 |
52 | #define PCPU 256 | 53 | #define PCPU 256 |
53 | 54 | #define ELAPSED 512 | |
54 | /* Different metrics */ | 55 | /* Different metrics */ |
55 | char *metric_name; | 56 | char *metric_name; |
56 | enum metric { | 57 | enum metric { |
57 | METRIC_PROCS, | 58 | METRIC_PROCS, |
58 | METRIC_VSZ, | 59 | METRIC_VSZ, |
59 | METRIC_RSS, | 60 | METRIC_RSS, |
60 | METRIC_CPU | 61 | METRIC_CPU, |
62 | METRIC_ELAPSED | ||
61 | }; | 63 | }; |
62 | enum metric metric = METRIC_PROCS; | 64 | enum metric metric = METRIC_PROCS; |
63 | 65 | ||
@@ -87,8 +89,10 @@ main (int argc, char **argv) | |||
87 | int procppid = 0; | 89 | int procppid = 0; |
88 | int procvsz = 0; | 90 | int procvsz = 0; |
89 | int procrss = 0; | 91 | int procrss = 0; |
92 | int procseconds = 0; | ||
90 | float procpcpu = 0; | 93 | float procpcpu = 0; |
91 | char procstat[8]; | 94 | char procstat[8]; |
95 | char procetime[MAX_INPUT_BUFFER]; | ||
92 | char *procargs; | 96 | char *procargs; |
93 | char *temp_string; | 97 | char *temp_string; |
94 | 98 | ||
@@ -174,10 +178,14 @@ main (int argc, char **argv) | |||
174 | temp_string = strtok (NULL, "/"); | 178 | temp_string = strtok (NULL, "/"); |
175 | } | 179 | } |
176 | 180 | ||
181 | /* we need to convert the elapsed time to seconds */ | ||
182 | procseconds = convert_to_seconds(procetime); | ||
183 | |||
177 | if (verbose >= 3) | 184 | if (verbose >= 3) |
178 | printf ("%d %d %d %d %d %.2f %s %s %s\n", | 185 | printf ("%d %d %d %d %d %.2f %s %s %s %s\n", |
179 | procs, procuid, procvsz, procrss, | 186 | procs, procuid, procvsz, procrss, |
180 | procppid, procpcpu, procstat, procprog, procargs); | 187 | procppid, procpcpu, procstat, |
188 | procetime, procprog, procargs); | ||
181 | 189 | ||
182 | /* Ignore self */ | 190 | /* Ignore self */ |
183 | if (strcmp (procprog, progname) == 0) { | 191 | if (strcmp (procprog, progname) == 0) { |
@@ -216,6 +224,8 @@ main (int argc, char **argv) | |||
216 | /* TODO? float thresholds for --metric=CPU */ | 224 | /* TODO? float thresholds for --metric=CPU */ |
217 | else if (metric == METRIC_CPU) | 225 | else if (metric == METRIC_CPU) |
218 | i = check_thresholds ((int)procpcpu); | 226 | i = check_thresholds ((int)procpcpu); |
227 | else if (metric == METRIC_ELAPSED) | ||
228 | i = check_thresholds (procseconds); | ||
219 | 229 | ||
220 | if (metric != METRIC_PROCS) { | 230 | if (metric != METRIC_PROCS) { |
221 | if (i == STATE_WARNING) { | 231 | if (i == STATE_WARNING) { |
@@ -312,6 +322,7 @@ process_arguments (int argc, char **argv) | |||
312 | {"vsz", required_argument, 0, 'z'}, | 322 | {"vsz", required_argument, 0, 'z'}, |
313 | {"rss", required_argument, 0, 'r'}, | 323 | {"rss", required_argument, 0, 'r'}, |
314 | {"pcpu", required_argument, 0, 'P'}, | 324 | {"pcpu", required_argument, 0, 'P'}, |
325 | {"elapsed", required_argument, 0, 'e'}, | ||
315 | {"argument-array", required_argument, 0, 'a'}, | 326 | {"argument-array", required_argument, 0, 'a'}, |
316 | {"help", no_argument, 0, 'h'}, | 327 | {"help", no_argument, 0, 'h'}, |
317 | {"version", no_argument, 0, 'V'}, | 328 | {"version", no_argument, 0, 'V'}, |
@@ -408,6 +419,7 @@ process_arguments (int argc, char **argv) | |||
408 | options |= USER; | 419 | options |= USER; |
409 | break; | 420 | break; |
410 | case 'C': /* command */ | 421 | case 'C': /* command */ |
422 | /* TODO: allow this to be passed in with --metric */ | ||
411 | if (prog) | 423 | if (prog) |
412 | break; | 424 | break; |
413 | else | 425 | else |
@@ -417,6 +429,7 @@ process_arguments (int argc, char **argv) | |||
417 | options |= PROG; | 429 | options |= PROG; |
418 | break; | 430 | break; |
419 | case 'a': /* args (full path name with args) */ | 431 | case 'a': /* args (full path name with args) */ |
432 | /* TODO: allow this to be passed in with --metric */ | ||
420 | if (args) | 433 | if (args) |
421 | break; | 434 | break; |
422 | else | 435 | else |
@@ -464,7 +477,12 @@ process_arguments (int argc, char **argv) | |||
464 | metric = METRIC_CPU; | 477 | metric = METRIC_CPU; |
465 | break; | 478 | break; |
466 | } | 479 | } |
467 | printf (_("%s: metric must be one of PROCS, VSZ, RSS, CPU!\n\n"), | 480 | else if ( strcmp(optarg, "ELAPSED") == 0) { |
481 | metric = METRIC_ELAPSED; | ||
482 | break; | ||
483 | } | ||
484 | |||
485 | printf (_("%s: metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!\n\n"), | ||
468 | progname); | 486 | progname); |
469 | print_usage (); | 487 | print_usage (); |
470 | exit (STATE_UNKNOWN); | 488 | exit (STATE_UNKNOWN); |
@@ -597,11 +615,15 @@ Required Arguments:\n\ | |||
597 | Optional Arguments:\n\ | 615 | Optional Arguments:\n\ |
598 | -m, --metric=TYPE\n\ | 616 | -m, --metric=TYPE\n\ |
599 | Check thresholds against metric. Valid types:\n\ | 617 | Check thresholds against metric. Valid types:\n\ |
600 | PROCS - number of processes (default)\n\ | 618 | PROCS - number of processes (default)\n\ |
601 | VSZ - virtual memory size\n\ | 619 | VSZ - virtual memory size\n\ |
602 | RSS - resident set memory size\n\ | 620 | RSS - resident set memory size\n\ |
603 | CPU - percentage cpu\n")); | 621 | CPU - percentage cpu\n")); |
604 | 622 | /* only linux etime is support currently */ | |
623 | #if defined( __linux__ ) | ||
624 | printf(_("\ | ||
625 | ELAPSED - time elapsed in seconds\n")); | ||
626 | #endif /* defined(__linux__) */ | ||
605 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | 627 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); |
606 | 628 | ||
607 | printf(_("\ | 629 | printf(_("\ |
@@ -654,13 +676,75 @@ Examples:\n\ | |||
654 | check_procs -w 50000 -c 100000 --metric=VSZ\n\ | 676 | check_procs -w 50000 -c 100000 --metric=VSZ\n\ |
655 | Alert if vsz of any processes over 50K or 100K\n\ | 677 | Alert if vsz of any processes over 50K or 100K\n\ |
656 | check_procs -w 10 -c 20 --metric=CPU\n\ | 678 | check_procs -w 10 -c 20 --metric=CPU\n\ |
657 | Alert if cpu of any processes over 10% or 20%\n\n")); | 679 | Alert if cpu of any processes over 10%% or 20%%\n\n")); |
658 | 680 | ||
659 | printf (_(UT_SUPPORT)); | 681 | printf (_(UT_SUPPORT)); |
660 | } | 682 | } |
661 | 683 | ||
662 | 684 | ||
663 | 685 | ||
686 | /* convert the elapsed time to seconds */ | ||
687 | int | ||
688 | convert_to_seconds(char *etime) { | ||
689 | |||
690 | char *ptr; | ||
691 | int total; | ||
692 | |||
693 | int hyphcnt; | ||
694 | int coloncnt; | ||
695 | int days; | ||
696 | int hours; | ||
697 | int minutes; | ||
698 | int seconds; | ||
699 | |||
700 | hyphcnt = 0; | ||
701 | coloncnt = 0; | ||
702 | days = 0; | ||
703 | hours = 0; | ||
704 | minutes = 0; | ||
705 | seconds = 0; | ||
706 | |||
707 | for (ptr = etime; *ptr != '\0'; ptr++) { | ||
708 | |||
709 | if (*ptr == '-') { | ||
710 | hyphcnt++; | ||
711 | continue; | ||
712 | } | ||
713 | if (*ptr == ':') { | ||
714 | coloncnt++; | ||
715 | continue; | ||
716 | } | ||
717 | } | ||
718 | |||
719 | if (hyphcnt > 0) { | ||
720 | sscanf(etime, "%d-%d:%d:%d", | ||
721 | &days, &hours, &minutes, &seconds); | ||
722 | /* linux 2.6.5/2.6.6 reporting some processes with infinite | ||
723 | * elapsed times for some reason */ | ||
724 | if (days == 49710) { | ||
725 | return 0; | ||
726 | } | ||
727 | } else { | ||
728 | if (coloncnt == 2) { | ||
729 | sscanf(etime, "%d:%d:%d", | ||
730 | &hours, &minutes, &seconds); | ||
731 | } else if (coloncnt == 1) { | ||
732 | sscanf(etime, "%d:%d", | ||
733 | &minutes, &seconds); | ||
734 | } | ||
735 | } | ||
736 | |||
737 | total = (days * 86400) + | ||
738 | (hours * 3600) + | ||
739 | (minutes * 60) + | ||
740 | seconds; | ||
741 | |||
742 | if (verbose >= 3) { | ||
743 | printf("seconds: %d\n", total); | ||
744 | } | ||
745 | return total; | ||
746 | } | ||
747 | |||
664 | void | 748 | void |
665 | print_usage (void) | 749 | print_usage (void) |
666 | { | 750 | { |