summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-11-18 11:24:00 +0000
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-11-18 11:24:00 +0000
commitc4e83a42c9b2fa09b1548a3c76e1a0f1d22bc30a (patch)
tree92b32f36e7780862ed2dc30ce9b957cad3e1af30
parent52c1c4d859b8dc711b9353c5f6373426f3b05efc (diff)
downloadmonitoring-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
-rw-r--r--plugins/check_swap.c51
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;
26int 26int
27main (int argc, char **argv) 27main (int argc, char **argv)
28{ 28{
29 int total_swap, used_swap, free_swap, percent_used; 29 int total_swap = 0, used_swap = 0, free_swap = 0, percent_used;
30 int total, used, free;
30 int result = STATE_OK; 31 int result = STATE_OK;
31 char input_buffer[MAX_INPUT_BUFFER]; 32 char input_buffer[MAX_INPUT_BUFFER];
32#ifdef HAVE_SWAP 33#ifdef HAVE_SWAP
@@ -36,7 +37,7 @@ main (int argc, char **argv)
36 FILE *fp; 37 FILE *fp;
37#endif 38#endif
38 char str[32]; 39 char str[32];
39 char *status = NULL; 40 char *status = "";
40 41
41 if (process_arguments (argc, argv) != OK) 42 if (process_arguments (argc, argv) != OK)
42 usage ("Invalid command arguments supplied\n"); 43 usage ("Invalid command arguments supplied\n");
@@ -45,19 +46,21 @@ main (int argc, char **argv)
45 fp = fopen (PROC_MEMINFO, "r"); 46 fp = fopen (PROC_MEMINFO, "r");
46 asprintf (&status, "%s", "Swap used:"); 47 asprintf (&status, "%s", "Swap used:");
47 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { 48 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
48 sscanf (input_buffer, " %s %d %d %d", str, &total_swap, &used_swap, 49 if (sscanf (input_buffer, " %s %d %d %d", str, &total, &used, &free) == 4 &&
49 &free_swap); 50 strstr (str, "Swap")) {
50 if (strstr (str, "Swap")) { 51/* asprintf (&status, "%s [%d/%d]", status, used, total); */
51 percent_used = 100 * (((float) used_swap) / ((float) total_swap)); 52 total_swap += total;
52 asprintf (&status, "%s %2d%% (%d bytes out of %d)", 53 used_swap += used;
53 status, percent_used, used_swap, total_swap); 54 free_swap += free;
54 if (percent_used >= crit_percent || free_swap <= crit_size)
55 result = STATE_CRITICAL;
56 else if (percent_used >= warn_percent || free_swap <= warn_size)
57 result = STATE_WARNING;
58 break;
59 } 55 }
60 } 56 }
57 percent_used = 100 * (((float) used_swap) / ((float) total_swap));
58 if (percent_used >= crit_percent || free_swap <= crit_size)
59 result = STATE_CRITICAL;
60 else if (percent_used >= warn_percent || free_swap <= warn_size)
61 result = STATE_WARNING;
62 asprintf (&status, "%s %2d%% (%d out of %d)", status, percent_used,
63 used_swap, total_swap);
61 fclose (fp); 64 fclose (fp);
62#else 65#else
63#ifdef HAVE_SWAP 66#ifdef HAVE_SWAP
@@ -89,16 +92,20 @@ main (int argc, char **argv)
89 92
90 asprintf (&status, "%s", "Swap used:"); 93 asprintf (&status, "%s", "Swap used:");
91 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 94 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
92 sscanf (input_buffer, SWAP_FORMAT, &total_swap, &free_swap); 95 sscanf (input_buffer, SWAP_FORMAT, &total, &free);
93 used_swap = total_swap - free_swap; 96 used = total - free;
94 percent_used = 100 * ((float) used_swap) / ((float) total_swap); 97/* asprintf (&status, "%s [%d/%d]", status, used, total); */
95 asprintf (&status, "%s %2d%% (%d bytes out of %d)", 98 total_swap += total;
96 status, percent_used, used_swap, total_swap); 99 used_swap += used;
97 if (percent_used >= crit_percent || free_swap <= crit_size) 100 free_swap += free;
98 result = STATE_CRITICAL;
99 else if (percent_used >= warn_percent || free_swap <= warn_size)
100 result = STATE_WARNING;
101 } 101 }
102 percent_used = 100 * ((float) used_swap) / ((float) total_swap);
103 asprintf (&status, "%s %2d%% (%d out of %d)",
104 status, percent_used, used_swap, total_swap);
105 if (percent_used >= crit_percent || free_swap <= crit_size)
106 result = STATE_CRITICAL;
107 else if (percent_used >= warn_percent || free_swap <= warn_size)
108 result = STATE_WARNING;
102 109
103 /* If we get anything on STDERR, at least set warning */ 110 /* If we get anything on STDERR, at least set warning */
104 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) 111 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))