From 1538fa84b575c8cc8fc19345c7bc597a2069f19d Mon Sep 17 00:00:00 2001 From: Kimo Rosenbaum Date: Tue, 24 Aug 2010 13:27:03 -0700 Subject: [PATCH] add support for sysctlbyname: vm.stats.sys.v_swtch --- configure.in | 1 + src/contextswitch.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 8ebf1244..d00ac98e 100644 --- a/configure.in +++ b/configure.in @@ -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" diff --git a/src/contextswitch.c b/src/contextswitch.c index 06055ca5..56d8bf09 100644 --- a/src/contextswitch.c +++ b/src/contextswitch.c @@ -23,7 +23,19 @@ #include "common.h" #include "plugin.h" -#if !KERNEL_LINUX +#ifdef HAVE_SYS_SYSCTL_H +# include +#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; } -- 2.11.0