[collectd] [PATCH 3/3] Remove LIBKSTAT support in swap plugin

collectd at wattapower.net collectd at wattapower.net
Tue May 4 15:05:14 CEST 2010


From: Aurélien Reynaud <collectd at wattapower.net>

This patch removes the libkstat-related code from the swap plugin.
Solaris support is now handled through swapctl.

Note that as a consequence the returned metrics are different.
"reserved" is no more, and "used" + "free" reflects the total
amount of on-disk swap space. This is in contrast to the libkstat
implementation where "used" + "free" + "reserved" added up to
more than on-disk swap, as it comprised a variable amount of RAM.
---
 src/swap.c |   58 ----------------------------------------------------------
 1 files changed, 0 insertions(+), 58 deletions(-)

diff --git a/src/swap.c b/src/swap.c
index 8ddf1e3..e7f3b9d 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -71,11 +71,6 @@
 /* No global variables */
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKSTAT
-static derive_t pagesize;
-static kstat_t *ksp;
-/* #endif HAVE_LIBKSTAT */
-
 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
 static derive_t pagesize;
 /* #endif HAVE_SWAPCTL */
@@ -108,13 +103,6 @@ static int swap_init (void)
 	/* No init stuff */
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKSTAT
-	/* getpagesize(3C) tells me this does not fail.. */
-	pagesize = (derive_t) getpagesize ();
-	if (get_kstat (&ksp, "unix", 0, "system_pages"))
-		ksp = NULL;
-/* #endif HAVE_LIBKSTAT */
-
 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
 	/* getpagesize(3C) tells me this does not fail.. */
 	pagesize = (derive_t) getpagesize ();
@@ -299,52 +287,6 @@ static int swap_read (void)
 	swap_submit ("out", swap_out, DS_TYPE_DERIVE);
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKSTAT
-	derive_t swap_alloc;
-	derive_t swap_resv;
-	derive_t swap_avail;
-
-	struct anoninfo ai;
-
-	if (swapctl (SC_AINFO, &ai) == -1)
-	{
-		char errbuf[1024];
-		ERROR ("swap plugin: swapctl failed: %s",
-				sstrerror (errno, errbuf, sizeof (errbuf)));
-		return (-1);
-	}
-
-	/*
-	 * Calculations from:
-	 * http://cvs.opensolaris.org/source/xref/on/usr/src/cmd/swap/swap.c
-	 * Also see:
-	 * http://www.itworld.com/Comp/2377/UIR980701perf/ (outdated?)
-	 * /usr/include/vm/anon.h
-	 *
-	 * In short, swap -s shows: allocated + reserved = used, available
-	 *
-	 * However, Solaris does not allow to allocated/reserved more than the
-	 * available swap (physical memory + disk swap), so the pedant may
-	 * prefer: allocated + unallocated = reserved, available
-	 *
-	 * We map the above to: used + resv = n/a, free
-	 *
-	 * Does your brain hurt yet?  - Christophe Kalt
-	 *
-	 * Oh, and in case you wonder,
-	 * swap_alloc = pagesize * ( ai.ani_max - ai.ani_free );
-	 * can suffer from a 32bit overflow.
-	 */
-	swap_alloc  = (derive_t) ((ai.ani_max - ai.ani_free) * pagesize);
-	swap_resv   = (derive_t) ((ai.ani_resv + ai.ani_free - ai.ani_max)
-			* pagesize);
-	swap_avail  = (derive_t) ((ai.ani_max - ai.ani_resv) * pagesize);
-
-	swap_submit ("used", swap_alloc, DS_TYPE_GAUGE);
-	swap_submit ("free", swap_avail, DS_TYPE_GAUGE);
-	swap_submit ("reserved", swap_resv, DS_TYPE_GAUGE);
-/* #endif HAVE_LIBKSTAT */
-
 #elif HAVE_SWAPCTL
  #if HAVE_SWAPCTL_TWO_ARGS
         swaptbl_t *s;
-- 
1.7.0.4




More information about the collectd mailing list