summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.in15
-rw-r--r--plugins/check_swap.c43
2 files changed, 33 insertions, 25 deletions
diff --git a/configure.in b/configure.in
index 0fdd8f6..37baafa 100644
--- a/configure.in
+++ b/configure.in
@@ -1248,17 +1248,12 @@ fi
1248dnl SWAP info required is amount allocated/available and amount free 1248dnl SWAP info required is amount allocated/available and amount free
1249dnl The plugin works through all the swap devices and adds up the total swap 1249dnl The plugin works through all the swap devices and adds up the total swap
1250dnl available. 1250dnl available.
1251AC_PATH_PROG(PATH_TO_SWAP,swap)
1252AC_PATH_PROG(PATH_TO_SWAPINFO,swapinfo)
1251 1253
1252dnl dunno why this does not work below - use hack (kbd) 1254dnl dunno why this does not work below - use hack (kbd)
1253dnl fine on linux, broken on solaris 1255dnl fine on linux, broken on solaris
1254dnl if /bin/test -e "/proc/meminfo" 1256dnl if /bin/test -e "/proc/meminfo"
1255
1256AC_PATH_PROG(PATH_TO_SWAP,swap)
1257AC_PATH_PROG(PATH_TO_SWAPINFO,swapinfo)
1258
1259if ( test -n "$PATH_TO_SWAP" || test -n "$PATH_TO_SWAPINFO" )
1260then
1261
1262AC_MSG_CHECKING(for how to check memory) 1257AC_MSG_CHECKING(for how to check memory)
1263if [cat /proc/meminfo > /dev/null 2>&1] 1258if [cat /proc/meminfo > /dev/null 2>&1]
1264then 1259then
@@ -1266,8 +1261,12 @@ then
1266 AC_DEFINE(HAVE_PROC_MEMINFO,1,[Define if we have /proc/meminfo]) 1261 AC_DEFINE(HAVE_PROC_MEMINFO,1,[Define if we have /proc/meminfo])
1267 AC_DEFINE_UNQUOTED(PROC_MEMINFO,"/proc/meminfo",[path to /proc/meminfo if name changes]) 1262 AC_DEFINE_UNQUOTED(PROC_MEMINFO,"/proc/meminfo",[path to /proc/meminfo if name changes])
1268 EXTRAS="$EXTRAS check_swap" 1263 EXTRAS="$EXTRAS check_swap"
1264fi
1265
1266if ( test -n "$PATH_TO_SWAP" || test -n "$PATH_TO_SWAPINFO" )
1267then
1269 1268
1270elif [$PATH_TO_SWAP -l 2>&1 >/dev/null] 1269if [$PATH_TO_SWAP -l 2>&1 >/dev/null]
1271then 1270then
1272 ac_cv_have_swap=yes 1271 ac_cv_have_swap=yes
1273 ac_cv_swap_command="$PATH_TO_SWAP -l" 1272 ac_cv_swap_command="$PATH_TO_SWAP -l"
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 3bbea77..3a799c3 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -59,14 +59,15 @@ main (int argc, char **argv)
59 long unsigned int dsktotal, dskused, dskfree; 59 long unsigned int dsktotal, dskused, dskfree;
60 int result = STATE_OK; 60 int result = STATE_OK;
61 char input_buffer[MAX_INPUT_BUFFER]; 61 char input_buffer[MAX_INPUT_BUFFER];
62#ifdef HAVE_SWAP 62#ifdef HAVE_PROC_MEMINFO
63 FILE *fp;
64#else
65# ifdef HAVE_SWAP
63 int conv_factor; /* Convert to MBs */ 66 int conv_factor; /* Convert to MBs */
64 char *temp_buffer; 67 char *temp_buffer;
65 char *swap_command; 68 char *swap_command;
66 char *swap_format; 69 char *swap_format;
67#endif 70# endif
68#ifdef HAVE_PROC_MEMINFO
69 FILE *fp;
70#endif 71#endif
71 char str[32]; 72 char str[32];
72 char *status; 73 char *status;
@@ -88,8 +89,20 @@ main (int argc, char **argv)
88 dsktotal = dsktotal / 1048576; 89 dsktotal = dsktotal / 1048576;
89 dskused = dskused / 1048576; 90 dskused = dskused / 1048576;
90 dskfree = dskfree / 1048576; 91 dskfree = dskfree / 1048576;
91#endif 92 total_swap += dsktotal;
92#ifdef HAVE_SWAP 93 used_swap += dskused;
94 free_swap += dskfree;
95 if (allswaps) {
96 percent = 100 * (((double) dskused) / ((double) dsktotal));
97 result = max_state (result, check_swap (percent, dskfree));
98 if (verbose)
99 asprintf (&status, "%s [%lu (%d%%)]", status, dskfree, 100 - percent);
100 }
101 }
102 }
103 fclose(fp);
104#else
105# ifdef HAVE_SWAP
93 if (!allswaps && sun) { 106 if (!allswaps && sun) {
94 asprintf(&swap_command, "%s", "/usr/sbin/swap -s"); 107 asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
95 asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s"); 108 asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
@@ -103,7 +116,7 @@ main (int argc, char **argv)
103 if (verbose >= 2) 116 if (verbose >= 2)
104 printf (_("Command: %s\n"), swap_command); 117 printf (_("Command: %s\n"), swap_command);
105 if (verbose >= 3) 118 if (verbose >= 3)
106 printf ("_(Format: %s\n"), swap_format); 119 printf (_("Format: %s\n"), swap_format);
107 120
108 child_process = spopen (swap_command); 121 child_process = spopen (swap_command);
109 if (child_process == NULL) { 122 if (child_process == NULL) {
@@ -146,7 +159,6 @@ main (int argc, char **argv)
146 printf (_("total=%d, free=%d\n"), dsktotal, dskfree); 159 printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
147 160
148 dskused = dsktotal - dskfree; 161 dskused = dsktotal - dskfree;
149#endif
150 total_swap += dsktotal; 162 total_swap += dsktotal;
151 used_swap += dskused; 163 used_swap += dskused;
152 free_swap += dskfree; 164 free_swap += dskfree;
@@ -158,15 +170,6 @@ main (int argc, char **argv)
158 } 170 }
159 } 171 }
160 } 172 }
161 percent_used = 100 * ((double) used_swap) / ((double) total_swap);
162 result = max_state (result, check_swap (percent_used, free_swap));
163 asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
164 (100 - percent_used), free_swap, total_swap, status);
165
166#ifdef HAVE_PROC_MEMINFO
167 fclose(fp);
168#endif
169#ifdef HAVE_SWAP
170 /* If we get anything on STDERR, at least set warning */ 173 /* If we get anything on STDERR, at least set warning */
171 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) 174 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
172 result = max_state (result, STATE_WARNING); 175 result = max_state (result, STATE_WARNING);
@@ -177,8 +180,14 @@ main (int argc, char **argv)
177 /* close the pipe */ 180 /* close the pipe */
178 if (spclose (child_process)) 181 if (spclose (child_process))
179 result = max_state (result, STATE_WARNING); 182 result = max_state (result, STATE_WARNING);
183# endif
180#endif 184#endif
181 185
186 percent_used = 100 * ((double) used_swap) / ((double) total_swap);
187 result = max_state (result, check_swap (percent_used, free_swap));
188 asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
189 (100 - percent_used), free_swap, total_swap, status);
190
182 die (result, "SWAP %s:%s\n", state_text (result), status); 191 die (result, "SWAP %s:%s\n", state_text (result), status);
183 return STATE_UNKNOWN; 192 return STATE_UNKNOWN;
184} 193}