summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 4d01a1c..a8a7d5e 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -32,6 +32,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
32int process_arguments (int, char **); 32int process_arguments (int, char **);
33int validate_arguments (void); 33int validate_arguments (void);
34int check_thresholds (int); 34int check_thresholds (int);
35int convert_to_seconds (char *);
35void print_help (void); 36void print_help (void);
36void print_usage (void); 37void 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 */
55char *metric_name; 56char *metric_name;
56enum metric { 57enum 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};
62enum metric metric = METRIC_PROCS; 64enum 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\
597Optional Arguments:\n\ 615Optional 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 */
687int
688convert_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
664void 748void
665print_usage (void) 749print_usage (void)
666{ 750{