diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2005-01-13 18:24:52 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2005-01-13 18:24:52 (GMT) |
commit | d866b45fdd8c41c7ff22f3aca35ce4b41f8e16a2 (patch) | |
tree | e19c214c58a75e37949d1b2bf873f761a39eeabf /plugins/check_swap.c | |
parent | 96c9d82e4c488cddca0d0f8cb71cd21f0b87e509 (diff) | |
download | monitoring-plugins-d866b45fdd8c41c7ff22f3aca35ce4b41f8e16a2.tar.gz |
Use floats for holding memory values to avoid different types on different
OSes. Seems to have a problem with the perf data for check_swap on Sol 2.6,
but not critical
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1080 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r-- | plugins/check_swap.c | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index bcc6b17..3396575 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -34,7 +34,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
34 | #include "popen.h" | 34 | #include "popen.h" |
35 | #include "utils.h" | 35 | #include "utils.h" |
36 | 36 | ||
37 | int check_swap (int usp, long unsigned int free_swap); | 37 | int check_swap (int usp, float free_swap); |
38 | int process_arguments (int argc, char **argv); | 38 | int process_arguments (int argc, char **argv); |
39 | int validate_arguments (void); | 39 | int validate_arguments (void); |
40 | void print_usage (void); | 40 | void print_usage (void); |
@@ -42,8 +42,8 @@ void print_help (void); | |||
42 | 42 | ||
43 | int warn_percent = 0; | 43 | int warn_percent = 0; |
44 | int crit_percent = 0; | 44 | int crit_percent = 0; |
45 | unsigned long long warn_size = 0; | 45 | float warn_size = 0; |
46 | unsigned long long crit_size = 0; | 46 | float crit_size = 0; |
47 | int verbose; | 47 | int verbose; |
48 | int allswaps; | 48 | int allswaps; |
49 | 49 | ||
@@ -51,8 +51,8 @@ int | |||
51 | main (int argc, char **argv) | 51 | main (int argc, char **argv) |
52 | { | 52 | { |
53 | int percent_used, percent; | 53 | int percent_used, percent; |
54 | unsigned long long total_swap = 0, used_swap = 0, free_swap = 0; | 54 | float total_swap = 0, used_swap = 0, free_swap = 0; |
55 | unsigned long long dsktotal = 0, dskused = 0, dskfree = 0, tmp = 0; | 55 | float dsktotal = 0, dskused = 0, dskfree = 0, tmp = 0; |
56 | int result = STATE_UNKNOWN; | 56 | int result = STATE_UNKNOWN; |
57 | char input_buffer[MAX_INPUT_BUFFER]; | 57 | char input_buffer[MAX_INPUT_BUFFER]; |
58 | char *perf; | 58 | char *perf; |
@@ -95,7 +95,7 @@ main (int argc, char **argv) | |||
95 | #ifdef HAVE_PROC_MEMINFO | 95 | #ifdef HAVE_PROC_MEMINFO |
96 | fp = fopen (PROC_MEMINFO, "r"); | 96 | fp = fopen (PROC_MEMINFO, "r"); |
97 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { | 97 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { |
98 | if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %llu %llu %llu", &dsktotal, &dskused, &dskfree) == 3) { | 98 | if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %f %f %f", &dsktotal, &dskused, &dskfree) == 3) { |
99 | dsktotal = dsktotal / 1048576; | 99 | dsktotal = dsktotal / 1048576; |
100 | dskused = dskused / 1048576; | 100 | dskused = dskused / 1048576; |
101 | dskfree = dskfree / 1048576; | 101 | dskfree = dskfree / 1048576; |
@@ -109,10 +109,10 @@ main (int argc, char **argv) | |||
109 | percent = 100 * (((double) dskused) / ((double) dsktotal)); | 109 | percent = 100 * (((double) dskused) / ((double) dsktotal)); |
110 | result = max_state (result, check_swap (percent, dskfree)); | 110 | result = max_state (result, check_swap (percent, dskfree)); |
111 | if (verbose) | 111 | if (verbose) |
112 | asprintf (&status, "%s [%llu (%d%%)]", status, dskfree, 100 - percent); | 112 | asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree, 100 - percent); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %llu %*[k]%*[B]", str, &tmp)) { | 115 | else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp)) { |
116 | if (strcmp ("Total", str) == 0) { | 116 | if (strcmp ("Total", str) == 0) { |
117 | dsktotal = tmp / 1024; | 117 | dsktotal = tmp / 1024; |
118 | } | 118 | } |
@@ -180,7 +180,7 @@ main (int argc, char **argv) | |||
180 | free_swap = total_swap * (100 - used_swap) /100; | 180 | free_swap = total_swap * (100 - used_swap) /100; |
181 | used_swap = total_swap - free_swap; | 181 | used_swap = total_swap - free_swap; |
182 | if (verbose >= 3) | 182 | if (verbose >= 3) |
183 | printf (_("total=%d, used=%d, free=%d\n"), total_swap, used_swap, free_swap); | 183 | printf (_("total=%.0f, used=%.0f, free=%.0f\n"), total_swap, used_swap, free_swap); |
184 | } else { | 184 | } else { |
185 | # endif | 185 | # endif |
186 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 186 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
@@ -194,7 +194,7 @@ main (int argc, char **argv) | |||
194 | dskfree = dskfree / conv_factor; | 194 | dskfree = dskfree / conv_factor; |
195 | # endif | 195 | # endif |
196 | if (verbose >= 3) | 196 | if (verbose >= 3) |
197 | printf (_("total=%llu, free=%llu\n"), dsktotal, dskfree); | 197 | printf (_("total=%.0f, free=%.0f\n"), dsktotal, dskfree); |
198 | 198 | ||
199 | dskused = dsktotal - dskfree; | 199 | dskused = dsktotal - dskfree; |
200 | total_swap += dsktotal; | 200 | total_swap += dsktotal; |
@@ -204,7 +204,7 @@ main (int argc, char **argv) | |||
204 | percent = 100 * (((double) dskused) / ((double) dsktotal)); | 204 | percent = 100 * (((double) dskused) / ((double) dsktotal)); |
205 | result = max_state (result, check_swap (percent, dskfree)); | 205 | result = max_state (result, check_swap (percent, dskfree)); |
206 | if (verbose) | 206 | if (verbose) |
207 | asprintf (&status, "%s [%llu (%d%%)]", status, dskfree, 100 - percent); | 207 | asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree, 100 - percent); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | # ifdef _AIX | 210 | # ifdef _AIX |
@@ -244,15 +244,18 @@ main (int argc, char **argv) | |||
244 | } | 244 | } |
245 | 245 | ||
246 | for(i=0;i<nswaps;i++){ | 246 | for(i=0;i<nswaps;i++){ |
247 | dsktotal = tbl->swt_ent[i].ste_pages / SWAP_CONVERSION; | 247 | dsktotal = (float) tbl->swt_ent[i].ste_pages / SWAP_CONVERSION; |
248 | dskfree = tbl->swt_ent[i].ste_free / SWAP_CONVERSION; | 248 | dskfree = (float) tbl->swt_ent[i].ste_free / SWAP_CONVERSION; |
249 | dskused = ( dsktotal - dskfree ); | 249 | dskused = ( dsktotal - dskfree ); |
250 | 250 | ||
251 | if (verbose >= 3) | ||
252 | printf ("dsktotal=%.0f dskfree=%.0f dskused=%.0f\n", dsktotal, dskfree, dskused); | ||
253 | |||
251 | if(allswaps && dsktotal > 0){ | 254 | if(allswaps && dsktotal > 0){ |
252 | percent = 100 * (((double) dskused) / ((double) dsktotal)); | 255 | percent = 100 * (((double) dskused) / ((double) dsktotal)); |
253 | result = max_state (result, check_swap (percent, dskfree)); | 256 | result = max_state (result, check_swap (percent, dskfree)); |
254 | if (verbose) { | 257 | if (verbose) { |
255 | asprintf (&status, "%s [%d (%d%%)]", status, (int)dskfree, 100 - percent); | 258 | asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree, 100 - percent); |
256 | } | 259 | } |
257 | } | 260 | } |
258 | 261 | ||
@@ -283,15 +286,15 @@ main (int argc, char **argv) | |||
283 | } | 286 | } |
284 | 287 | ||
285 | for(i=0;i<nswaps;i++){ | 288 | for(i=0;i<nswaps;i++){ |
286 | dsktotal = ent->se_nblks / conv_factor; | 289 | dsktotal = (float) ent->se_nblks / conv_factor; |
287 | dskused = ent->se_inuse / conv_factor; | 290 | dskused = (float) ent->se_inuse / conv_factor; |
288 | dskfree = ( dsktotal - dskused ); | 291 | dskfree = ( dsktotal - dskused ); |
289 | 292 | ||
290 | if(allswaps && dsktotal > 0){ | 293 | if(allswaps && dsktotal > 0){ |
291 | percent = 100 * (((double) dskused) / ((double) dsktotal)); | 294 | percent = 100 * (((double) dskused) / ((double) dsktotal)); |
292 | result = max_state (result, check_swap (percent, dskfree)); | 295 | result = max_state (result, check_swap (percent, dskfree)); |
293 | if (verbose) { | 296 | if (verbose) { |
294 | asprintf (&status, "%s [%d (%d%%)]", status, (int)dskfree, 100 - percent); | 297 | asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree, 100 - percent); |
295 | } | 298 | } |
296 | } | 299 | } |
297 | 300 | ||
@@ -311,7 +314,7 @@ main (int argc, char **argv) | |||
311 | percent_used = 100 * ((double) used_swap) / ((double) total_swap); | 314 | percent_used = 100 * ((double) used_swap) / ((double) total_swap); |
312 | result = max_state (result, check_swap (percent_used, free_swap)); | 315 | result = max_state (result, check_swap (percent_used, free_swap)); |
313 | /* broken into two steps because of funkiness with builtin asprintf */ | 316 | /* broken into two steps because of funkiness with builtin asprintf */ |
314 | asprintf (&tmp_status, _(" %d%% free (%llu MB out of %llu MB)"), | 317 | asprintf (&tmp_status, _(" %d%% free (%.0f MB out of %.0f MB)"), |
315 | (100 - percent_used), free_swap, total_swap); | 318 | (100 - percent_used), free_swap, total_swap); |
316 | asprintf (&status, "%s%s", tmp_status, status); | 319 | asprintf (&status, "%s%s", tmp_status, status); |
317 | 320 | ||
@@ -327,7 +330,7 @@ main (int argc, char **argv) | |||
327 | 330 | ||
328 | 331 | ||
329 | int | 332 | int |
330 | check_swap (int usp, long unsigned int free_swap) | 333 | check_swap (int usp, float free_swap) |
331 | { | 334 | { |
332 | int result = STATE_UNKNOWN; | 335 | int result = STATE_UNKNOWN; |
333 | free_swap = free_swap * 1024; /* Convert back to bytes as warn and crit specified in bytes */ | 336 | free_swap = free_swap * 1024; /* Convert back to bytes as warn and crit specified in bytes */ |
@@ -375,12 +378,12 @@ process_arguments (int argc, char **argv) | |||
375 | switch (c) { | 378 | switch (c) { |
376 | case 'w': /* warning size threshold */ | 379 | case 'w': /* warning size threshold */ |
377 | if (is_intnonneg (optarg)) { | 380 | if (is_intnonneg (optarg)) { |
378 | warn_size = atoi (optarg); | 381 | warn_size = (float) atoi (optarg); |
379 | break; | 382 | break; |
380 | } | 383 | } |
381 | else if (strstr (optarg, ",") && | 384 | else if (strstr (optarg, ",") && |
382 | strstr (optarg, "%") && | 385 | strstr (optarg, "%") && |
383 | sscanf (optarg, "%llu,%d%%", &warn_size, &warn_percent) == 2) { | 386 | sscanf (optarg, "%.0f,%d%%", &warn_size, &warn_percent) == 2) { |
384 | break; | 387 | break; |
385 | } | 388 | } |
386 | else if (strstr (optarg, "%") && | 389 | else if (strstr (optarg, "%") && |
@@ -392,12 +395,12 @@ process_arguments (int argc, char **argv) | |||
392 | } | 395 | } |
393 | case 'c': /* critical size threshold */ | 396 | case 'c': /* critical size threshold */ |
394 | if (is_intnonneg (optarg)) { | 397 | if (is_intnonneg (optarg)) { |
395 | crit_size = atoi (optarg); | 398 | crit_size = (float) atoi (optarg); |
396 | break; | 399 | break; |
397 | } | 400 | } |
398 | else if (strstr (optarg, ",") && | 401 | else if (strstr (optarg, ",") && |
399 | strstr (optarg, "%") && | 402 | strstr (optarg, "%") && |
400 | sscanf (optarg, "%llu,%d%%", &crit_size, &crit_percent) == 2) { | 403 | sscanf (optarg, "%.0f,%d%%", &crit_size, &crit_percent) == 2) { |
401 | break; | 404 | break; |
402 | } | 405 | } |
403 | else if (strstr (optarg, "%") && | 406 | else if (strstr (optarg, "%") && |
@@ -438,7 +441,7 @@ process_arguments (int argc, char **argv) | |||
438 | if (c == argc) | 441 | if (c == argc) |
439 | return validate_arguments (); | 442 | return validate_arguments (); |
440 | if (warn_size == 0 && is_intnonneg (argv[c])) | 443 | if (warn_size == 0 && is_intnonneg (argv[c])) |
441 | warn_size = atoi (argv[c++]); | 444 | warn_size = (float) atoi (argv[c++]); |
442 | 445 | ||
443 | if (c == argc) | 446 | if (c == argc) |
444 | return validate_arguments (); | 447 | return validate_arguments (); |