[Nagiosplug-devel] [patch] check_swap: tru64 support (swapctl(2) syscall)

sean finney seanius at seanius.net
Wed Aug 18 21:57:08 CEST 2004


hey folks,

attached is a patch to the latest cvs that adds support to check_swap
for tru64 systems, via the swapctl(2) syscall.  this syscall also
exists on solaris with the same calling convention, and a slightly
different one exists on *bsd, but for this patch it will only affect
systems which don't pass any of the previous configure tests (thus
only tru64 to my knowledge).

the next patch i'll submit will include reworked code for these
other systems, as well as using linux's sysinfo(2) for similar
purposes.


	sean

ps - i'm now subscribed to the list, so no need to keep cc'ing me
-------------- next part --------------
Index: configure.in
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/configure.in,v
retrieving revision 1.111
diff -u -r1.111 configure.in
--- configure.in	18 Aug 2004 20:36:07 -0000	1.111
+++ configure.in	19 Aug 2004 04:09:44 -0000
@@ -1388,6 +1388,23 @@
 dnl end if for PATH_TO_SWAPCTL
 fi
 
+dnl
+dnl test for swapctl system call, as found in tru64 and solaris
+dnl note: the way the ifdef logic in check_swap is right now,
+dnl this will only affect systems that don't pass one of the
+dnl earlier tests.
+dnl
+AC_CHECK_HEADERS([sys/swap.h sys/stat.h sys/param.h])
+AC_CHECK_DECLS([swapctl],,,[
+	#include <sys/types.h>
+	#include <sys/stat.h>
+	#include <sys/swap.h>
+	])
+dnl
+dnl end test for swapctl system call
+dnl
+
+
 if test "x$ac_cv_have_swap" != "x" 
 then
 	AC_DEFINE(HAVE_SWAP,1,[Define if swap/swapinfo command is found])
Index: plugins/check_swap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_swap.c,v
retrieving revision 1.29
diff -u -r1.29 check_swap.c
--- plugins/check_swap.c	2 Mar 2004 05:01:19 -0000	1.29
+++ plugins/check_swap.c	19 Aug 2004 04:09:45 -0000
@@ -52,7 +52,7 @@
 {
 	int percent_used, percent;
 	unsigned long long total_swap = 0, used_swap = 0, free_swap = 0;
-	unsigned long long dsktotal, dskused, dskfree, tmp;
+	unsigned long long dsktotal = 0, dskused = 0, dskfree = 0, tmp = 0;
 	int result = STATE_OK;
 	char input_buffer[MAX_INPUT_BUFFER];
 	char *perf;
@@ -64,6 +64,11 @@
 	char *temp_buffer;
 	char *swap_command;
 	char *swap_format;
+# else
+#  ifdef HAVE_DECL_SWAPCTL
+	int i=0, nswaps=0;
+	swaptbl_t tbl;
+#  endif /* HAVE_DECL_SWAPCTL */
 # endif
 #endif
 	char str[32];
@@ -230,6 +235,43 @@
 	/* close the pipe */
 	if (spclose (child_process))
 		result = max_state (result, STATE_WARNING);
+# else
+#  ifdef HAVE_DECL_SWAPCTL
+
+	/* initialize swap table entries */
+	memset(&tbl, 0, sizeof(swaptbl_t));
+	tbl.swt_ent[0].ste_path=(char*)malloc(sizeof(char)*(MAXPATHLEN+1));
+	memset(tbl.swt_ent[0].ste_path, 0, sizeof(char)*(MAXPATHLEN+1));
+	tbl.swt_n=1;
+
+	/* get the number of active swap devices */
+	nswaps=swapctl(SC_GETNSWP, NULL);
+
+	/* and now, tally 'em up */
+	for(i=0;i<nswaps;i++){
+		swapctl(SC_LIST, &tbl);
+		/* on tru64, swap is stored in 8k pages.  i'd
+		   use conv_factor or SWAP_CONVERSION, but they're
+		   both buried under a bunch of ifdef's.  ideally
+		   all functions could call getpagesize(2)...  */
+		dsktotal = tbl.swt_ent[0].ste_pages / 128;
+		dskfree = tbl.swt_ent[0].ste_free / 128;
+		dskused = ( total_swap - free_swap );
+
+		if(allswaps && dsktotal > 0){
+			percent = 100 * (((double) dskused) / ((double) dsktotal));
+			result = max_state (result, check_swap (percent, dskfree));
+		}
+
+		total_swap += dsktotal;
+		free_swap += dskfree;
+		used_swap += dskused;
+	}
+
+	/* and clean up after ourselves */
+	free(tbl.swt_ent[0].ste_path);
+
+#  endif /* HAVE_DECL_SWAPCTL */
 # endif /* HAVE_SWAP */
 #endif /* HAVE_PROC_MEMINFO */
 
Index: plugins/common.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/common.h,v
retrieving revision 1.11
diff -u -r1.11 common.h
--- plugins/common.h	24 Oct 2003 13:28:24 -0000	1.11
+++ plugins/common.h	19 Aug 2004 04:09:45 -0000
@@ -98,6 +98,18 @@
 #include <locale.h>
 #endif
 
+#ifdef HAVE_DECL_SWAPCTL
+# ifdef HAVE_SYS_SWAP_H
+#  include <sys/swap.h>
+# endif
+# ifdef HAVE_SYS_STAT_H
+#  include <sys/stat.h>
+# endif
+# ifdef HAVE_SYS_PARAM_H
+#  include <sys/param.h>
+# endif
+#endif
+
 /*
  *
  * Missing Functions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20040818/feea6a6a/attachment.sig>


More information about the Devel mailing list