summaryrefslogtreecommitdiffstats
path: root/plugins/check_vsz.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2003-04-07 22:53:49 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2003-04-07 22:53:49 +0000
commit1a6c23309c5e57af28f6465610d98a6fc834c429 (patch)
tree740969fb573f9eaea4c6a0f10d0fce0fb71fea21 /plugins/check_vsz.c
parent8fa5d6d877b9810967396dd27dc6e0b7665ec2fa (diff)
downloadmonitoring-plugins-1a6c23309c5e57af28f6465610d98a6fc834c429.tar.gz
Souped up check_procs with different metrics
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@474 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_vsz.c')
-rw-r--r--plugins/check_vsz.c250
1 files changed, 0 insertions, 250 deletions
diff --git a/plugins/check_vsz.c b/plugins/check_vsz.c
deleted file mode 100644
index 7a9acb2d..00000000
--- a/plugins/check_vsz.c
+++ /dev/null
@@ -1,250 +0,0 @@
1/******************************************************************************
2 *
3 * CHECK_VSZ.C
4 *
5 * Program: Process plugin for Nagios
6 * License: GPL
7 * Copyright (c) 1999,2000 Karl DeBisschop <kdebiss@alum.mit.edu>
8 *
9 * Last Modified: $Date$
10 *
11 * Description:
12 *
13 * This plugin will check for processes whose total image size exceeds
14 * the warning or critical thresholds given on the command line. With
15 * no command_name, everything that shows up on ps is evaluated.
16 * Otherwise, only jobs with the command_name given are examined.
17 * This program is particularly useful if you have to run a piece of
18 * commercial software that has a memory leak. With it you can shut
19 * down and restart the processes whenever the program threatens to
20 * take over your system.
21 *
22 * Modifications:
23 *
24 * 11-18-1999 Karl DeBisschop (kdebiss@alum.mit.edu)
25 * change to getopt, use print_help
26 * 08-18-1999 Ethan Galstad (nagios@nagios.org)
27 * Changed code to use common include file
28 * Changed fclose() to pclose()
29 * 09-09-1999 Ethan Galstad (nagios@nagios.org)
30 * Changed popen()/pclose() to spopen()/spclose()
31 * 11-18-1999 Karl DeBisschop (kdebiss@alum.mit.edu)
32 * set STATE_WARNING of stderr written or nonzero status returned
33 *
34 *****************************************************************************/
35
36const char *progname = "check_vsz";
37#define REVISION "$Revision$"
38#define COPYRIGHT "1999-2002"
39#define AUTHOR "Karl DeBisschop"
40#define EMAIL "karl@debisschop.net"
41#define SUMMARY "Check the image size of a running program.\n"
42
43#include "common.h"
44#include "popen.h"
45#include "utils.h"
46
47int process_arguments (int argc, char **argv);
48void print_help (const char *cmd);
49void print_usage (const char *cmd);
50
51int warn = -1;
52int crit = -1;
53char *proc = NULL;
54
55int
56main (int argc, char **argv)
57{
58 int len;
59 int result = STATE_OK;
60 int line = 0;
61 int proc_size = -1;
62 char input_buffer[MAX_INPUT_BUFFER];
63 char proc_name[MAX_INPUT_BUFFER];
64 char *message = "";
65
66 if (process_arguments (argc, argv) == ERROR) {
67 printf ("%s: failure parsing arguments\n", progname);
68 print_help (progname);
69 return STATE_UNKNOWN;
70 }
71
72 /* run the command */
73 child_process = spopen (VSZ_COMMAND);
74 if (child_process == NULL) {
75 printf ("Unable to open pipe: %s\n", VSZ_COMMAND);
76 return STATE_UNKNOWN;
77 }
78
79 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
80 if (child_stderr == NULL)
81 printf ("Could not open stderr for %s\n", VSZ_COMMAND);
82
83 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
84
85 line++;
86
87 /* skip the first line */
88 if (line == 1)
89 continue;
90
91 if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) {
92 if (proc == NULL) {
93 if (proc_size > warn) {
94 asprintf (&message, "%s %s(%d)", message, proc_name, proc_size);
95 result = max_state (result, STATE_WARNING);
96 }
97 if (proc_size > crit) {
98 result = STATE_CRITICAL;
99 }
100 }
101 else if (strstr (proc_name, proc)) {
102 asprintf (&message, "%s %d", message, proc_size);
103 if (proc_size > warn) {
104 result = max_state (result, STATE_WARNING);
105 }
106 if (proc_size > crit) {
107 result = STATE_CRITICAL;
108 }
109 }
110 }
111 }
112
113 /* If we get anything on STDERR, at least set warning */
114 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
115 result = max_state (result, STATE_WARNING);
116
117 (void) fclose (child_stderr);
118
119 /* close the pipe */
120 if (spclose (child_process))
121 result = max_state (result, STATE_WARNING);
122
123 if (result == STATE_OK)
124 printf ("ok (all VSZ<%d): %s\n", warn, message);
125 else if (result == STATE_UNKNOWN)
126 printf ("Unable to read output\n");
127 else if (result == STATE_WARNING)
128 printf ("WARNING (VSZ>%d):%s\n", warn, message);
129 else
130 printf ("CRITICAL (VSZ>%d):%s\n", crit, message);
131
132 return result;
133}
134
135
136
137
138int
139process_arguments (int argc, char **argv)
140{
141 int c;
142
143 int option_index = 0;
144 static struct option long_options[] = {
145 {"help", no_argument, 0, 'h'},
146 {"version", no_argument, 0, 'V'},
147 {"critical", required_argument, 0, 'c'},
148 {"warning", required_argument, 0, 'w'},
149 {"command", required_argument, 0, 'C'},
150 {0, 0, 0, 0}
151 };
152
153 if (argc < 2)
154 return ERROR;
155
156 while (1) {
157 c = getopt_long (argc, argv, "+hVc:w:C:", long_options, &option_index);
158
159 if (c == EOF)
160 break;
161
162 switch (c) {
163 case '?': /* help */
164 print_usage (progname);
165 exit (STATE_UNKNOWN);
166 case 'h': /* help */
167 print_help (progname);
168 exit (STATE_OK);
169 case 'V': /* version */
170 print_revision (progname, "$Revision$");
171 exit (STATE_OK);
172 case 'c': /* critical threshold */
173 if (!is_intnonneg (optarg)) {
174 printf ("%s: critical threshold must be an integer: %s\n",
175 progname, optarg);
176 print_usage (progname);
177 exit (STATE_UNKNOWN);
178 }
179 crit = atoi (optarg);
180 break;
181 case 'w': /* warning threshold */
182 if (!is_intnonneg (optarg)) {
183 printf ("%s: warning threshold must be an integer: %s\n",
184 progname, optarg);
185 print_usage (progname);
186 exit (STATE_UNKNOWN);
187 }
188 warn = atoi (optarg);
189 break;
190 case 'C': /* command name */
191 proc = optarg;
192 break;
193 }
194 }
195
196 c = optind;
197 if (warn == -1) {
198 if (!is_intnonneg (argv[c])) {
199 printf ("%s: critical threshold must be an integer: %s\n",
200 progname, argv[c]);
201 print_usage (progname);
202 exit (STATE_UNKNOWN);
203 }
204 warn = atoi (argv[c++]);
205 }
206
207 if (crit == -1) {
208 if (!is_intnonneg (argv[c])) {
209 printf ("%s: critical threshold must be an integer: %s\n",
210 progname, argv[c]);
211 print_usage (progname);
212 exit (STATE_UNKNOWN);
213 }
214 crit = atoi (argv[c++]);
215 }
216
217 if (proc == NULL)
218 proc = argv[c];
219
220 return c;
221}
222
223void
224print_usage (const char *cmd)
225{
226 printf ("Usage: %s -w <wsize> -c <csize> [-C command]\n"
227 " %s --help\n" " %s --version\n", cmd, cmd, cmd);
228}
229
230void
231print_help (const char *cmd)
232{
233 print_revision ("check_vsz", "$Revision$");
234 printf
235 ("Copyright (c) 2000 Karl DeBisschop <kdebiss@alum.mit.edu>\n\n"
236 "This plugin checks the image size of a running program and returns an\n"
237 "error if the number is above either of the thresholds given.\n\n");
238 print_usage (cmd);
239 printf
240 ("\nOptions:\n"
241 " -h, --help\n"
242 " Print detailed help\n"
243 " -V, --version\n"
244 " Print version numbers and license information\n"
245 " -w, --warning=INTEGER\n"
246 " Program image size necessary to cause a WARNING state\n"
247 " -c, --critical=INTEGER\n"
248 " Program image size necessary to cause a CRITICAL state\n"
249 " -C, --command=STRING\n" " Program to search for [optional]\n");
250}