Code

add support for sysctlbyname: vm.stats.sys.v_swtch
authorKimo Rosenbaum <kimo@Kimo-Rosenbaums-MacBook-Pro.local>
Tue, 24 Aug 2010 20:27:03 +0000 (13:27 -0700)
committerKimo Rosenbaum <kimo@Kimo-Rosenbaums-MacBook-Pro.local>
Tue, 24 Aug 2010 20:27:03 +0000 (13:27 -0700)
configure.in
src/contextswitch.c

index 8ebf124447cd89225c894dd392f43999dcfae226..d00ac98ed9b6e6e1bead6cf8caf95887f7ec84b0 100644 (file)
@@ -4334,6 +4334,7 @@ then
 fi
 if test "x$have_sysctlbyname" = "xyes"
 then
+       plugin_contextswitch="yes"
        plugin_cpu="yes"
        plugin_memory="yes"
        plugin_tcpconns="yes"
index 06055ca59372299616a6f8b1bf105d30e34760f4..56d8bf09ee490f79bf148eaff6d67947ad98d1f2 100644 (file)
 #include "common.h"
 #include "plugin.h"
 
-#if !KERNEL_LINUX
+#ifdef HAVE_SYS_SYSCTL_H
+# include <sys/sysctl.h>
+#endif
+
+#if HAVE_SYSCTLBYNAME
+/* no global variables */
+/* #endif HAVE_SYSCTLBYNAME */
+
+#elif KERNEL_LINUX
+/* no global variables */
+/* #endif KERNEL_LINUX */
+
+#else
 # error "No applicable input method."
 #endif
 
@@ -45,12 +57,29 @@ static void cs_submit (derive_t context_switches)
 
 static int cs_read (void)
 {
+       int status = -2;
+#if HAVE_SYSCTLBYNAME
+       int value;
+       size_t value_len = sizeof (value);
+
+       if (sysctlbyname ("vm.stats.sys.v_swtch", (void *) &value, &value_len,
+                       NULL, 0) == 0)
+       {
+               cs_submit(value);
+               status = 0;
+       }
+       else
+       {
+               ERROR("contextswitch plugin: sysctlbyname failed");
+       }
+
+/* #endif HAVE_SYSCTLBYNAME */
+#elif KERNEL_LINUX
        FILE *fh;
        char buffer[64];
        int numfields;
        char *fields[3];
        derive_t result = 0;
-       int status = -2;
 
        fh = fopen ("/proc/stat", "r");
        if (fh == NULL) {
@@ -88,6 +117,7 @@ static int cs_read (void)
 
        if (status == -2)
                ERROR ("contextswitch plugin: Unable to find context switch value.");
+#endif /* KERNEL_LINUX */
 
        return status;
 }