diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-18 11:24:00 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-18 11:24:00 +0000 |
commit | c4e83a42c9b2fa09b1548a3c76e1a0f1d22bc30a (patch) | |
tree | 92b32f36e7780862ed2dc30ce9b957cad3e1af30 /plugins/check_swap.c | |
parent | 52c1c4d859b8dc711b9353c5f6373426f3b05efc (diff) | |
download | monitoring-plugins-c4e83a42c9b2fa09b1548a3c76e1a0f1d22bc30a.tar.gz |
test total swap instead of individual disks
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@209 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r-- | plugins/check_swap.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 8e0a5898..da18ccb8 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -26,7 +26,8 @@ int warn_percent = 200, crit_percent = 200, warn_size = -1, crit_size = -1; int main (int argc, char **argv) { - int total_swap, used_swap, free_swap, percent_used; + int total_swap = 0, used_swap = 0, free_swap = 0, percent_used; + int total, used, free; int result = STATE_OK; char input_buffer[MAX_INPUT_BUFFER]; #ifdef HAVE_SWAP @@ -36,7 +37,7 @@ main (int argc, char **argv) FILE *fp; #endif char str[32]; - char *status = NULL; + char *status = ""; if (process_arguments (argc, argv) != OK) usage ("Invalid command arguments supplied\n"); @@ -45,19 +46,21 @@ main (int argc, char **argv) fp = fopen (PROC_MEMINFO, "r"); asprintf (&status, "%s", "Swap used:"); while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { - sscanf (input_buffer, " %s %d %d %d", str, &total_swap, &used_swap, - &free_swap); - if (strstr (str, "Swap")) { - percent_used = 100 * (((float) used_swap) / ((float) total_swap)); - asprintf (&status, "%s %2d%% (%d bytes out of %d)", - status, percent_used, used_swap, total_swap); - if (percent_used >= crit_percent || free_swap <= crit_size) - result = STATE_CRITICAL; - else if (percent_used >= warn_percent || free_swap <= warn_size) - result = STATE_WARNING; - break; + if (sscanf (input_buffer, " %s %d %d %d", str, &total, &used, &free) == 4 && + strstr (str, "Swap")) { +/* asprintf (&status, "%s [%d/%d]", status, used, total); */ + total_swap += total; + used_swap += used; + free_swap += free; } } + percent_used = 100 * (((float) used_swap) / ((float) total_swap)); + if (percent_used >= crit_percent || free_swap <= crit_size) + result = STATE_CRITICAL; + else if (percent_used >= warn_percent || free_swap <= warn_size) + result = STATE_WARNING; + asprintf (&status, "%s %2d%% (%d out of %d)", status, percent_used, + used_swap, total_swap); fclose (fp); #else #ifdef HAVE_SWAP @@ -89,16 +92,20 @@ main (int argc, char **argv) asprintf (&status, "%s", "Swap used:"); while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { - sscanf (input_buffer, SWAP_FORMAT, &total_swap, &free_swap); - used_swap = total_swap - free_swap; - percent_used = 100 * ((float) used_swap) / ((float) total_swap); - asprintf (&status, "%s %2d%% (%d bytes out of %d)", - status, percent_used, used_swap, total_swap); - if (percent_used >= crit_percent || free_swap <= crit_size) - result = STATE_CRITICAL; - else if (percent_used >= warn_percent || free_swap <= warn_size) - result = STATE_WARNING; + sscanf (input_buffer, SWAP_FORMAT, &total, &free); + used = total - free; +/* asprintf (&status, "%s [%d/%d]", status, used, total); */ + total_swap += total; + used_swap += used; + free_swap += free; } + percent_used = 100 * ((float) used_swap) / ((float) total_swap); + asprintf (&status, "%s %2d%% (%d out of %d)", + status, percent_used, used_swap, total_swap); + if (percent_used >= crit_percent || free_swap <= crit_size) + result = STATE_CRITICAL; + else if (percent_used >= warn_percent || free_swap <= warn_size) + result = STATE_WARNING; /* If we get anything on STDERR, at least set warning */ while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) |