summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fee4763)
raw | patch | inline | side by side (parent: fee4763)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Thu, 11 Sep 2003 08:02:04 +0000 (08:02 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Thu, 11 Sep 2003 08:02:04 +0000 (08:02 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@716 f882894a-f735-0410-b71e-b25c423dba1c
configure.in | patch | blob | history | |
plugins/check_swap.c | patch | blob | history |
diff --git a/configure.in b/configure.in
index 0fdd8f639adddd6a696e448eaf7a7a6bb2346f8d..37baafa8e741979d071c4806a8e8c403154669a3 100644 (file)
--- a/configure.in
+++ b/configure.in
dnl SWAP info required is amount allocated/available and amount free
dnl The plugin works through all the swap devices and adds up the total swap
dnl available.
+AC_PATH_PROG(PATH_TO_SWAP,swap)
+AC_PATH_PROG(PATH_TO_SWAPINFO,swapinfo)
dnl dunno why this does not work below - use hack (kbd)
dnl fine on linux, broken on solaris
dnl if /bin/test -e "/proc/meminfo"
-
-AC_PATH_PROG(PATH_TO_SWAP,swap)
-AC_PATH_PROG(PATH_TO_SWAPINFO,swapinfo)
-
-if ( test -n "$PATH_TO_SWAP" || test -n "$PATH_TO_SWAPINFO" )
-then
-
AC_MSG_CHECKING(for how to check memory)
if [cat /proc/meminfo > /dev/null 2>&1]
then
AC_DEFINE(HAVE_PROC_MEMINFO,1,[Define if we have /proc/meminfo])
AC_DEFINE_UNQUOTED(PROC_MEMINFO,"/proc/meminfo",[path to /proc/meminfo if name changes])
EXTRAS="$EXTRAS check_swap"
+fi
+
+if ( test -n "$PATH_TO_SWAP" || test -n "$PATH_TO_SWAPINFO" )
+then
-elif [$PATH_TO_SWAP -l 2>&1 >/dev/null]
+if [$PATH_TO_SWAP -l 2>&1 >/dev/null]
then
ac_cv_have_swap=yes
ac_cv_swap_command="$PATH_TO_SWAP -l"
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 3bbea77bd7c34655947e956f36d47932b305cf02..3a799c32ea47857e702acb72800b0edcfc06f355 100644 (file)
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
long unsigned int dsktotal, dskused, dskfree;
int result = STATE_OK;
char input_buffer[MAX_INPUT_BUFFER];
-#ifdef HAVE_SWAP
+#ifdef HAVE_PROC_MEMINFO
+ FILE *fp;
+#else
+# ifdef HAVE_SWAP
int conv_factor; /* Convert to MBs */
char *temp_buffer;
char *swap_command;
char *swap_format;
-#endif
-#ifdef HAVE_PROC_MEMINFO
- FILE *fp;
+# endif
#endif
char str[32];
char *status;
dsktotal = dsktotal / 1048576;
dskused = dskused / 1048576;
dskfree = dskfree / 1048576;
-#endif
-#ifdef HAVE_SWAP
+ total_swap += dsktotal;
+ used_swap += dskused;
+ free_swap += dskfree;
+ if (allswaps) {
+ percent = 100 * (((double) dskused) / ((double) dsktotal));
+ result = max_state (result, check_swap (percent, dskfree));
+ if (verbose)
+ asprintf (&status, "%s [%lu (%d%%)]", status, dskfree, 100 - percent);
+ }
+ }
+ }
+ fclose(fp);
+#else
+# ifdef HAVE_SWAP
if (!allswaps && sun) {
asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
if (verbose >= 2)
printf (_("Command: %s\n"), swap_command);
if (verbose >= 3)
- printf ("_(Format: %s\n"), swap_format);
+ printf (_("Format: %s\n"), swap_format);
child_process = spopen (swap_command);
if (child_process == NULL) {
printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
dskused = dsktotal - dskfree;
-#endif
total_swap += dsktotal;
used_swap += dskused;
free_swap += dskfree;
}
}
}
- percent_used = 100 * ((double) used_swap) / ((double) total_swap);
- result = max_state (result, check_swap (percent_used, free_swap));
- asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
- (100 - percent_used), free_swap, total_swap, status);
-
-#ifdef HAVE_PROC_MEMINFO
- fclose(fp);
-#endif
-#ifdef HAVE_SWAP
/* If we get anything on STDERR, at least set warning */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
result = max_state (result, STATE_WARNING);
/* close the pipe */
if (spclose (child_process))
result = max_state (result, STATE_WARNING);
+# endif
#endif
+ percent_used = 100 * ((double) used_swap) / ((double) total_swap);
+ result = max_state (result, check_swap (percent_used, free_swap));
+ asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
+ (100 - percent_used), free_swap, total_swap, status);
+
die (result, "SWAP %s:%s\n", state_text (result), status);
return STATE_UNKNOWN;
}