From: octo Date: Wed, 7 Jun 2006 17:11:52 +0000 (+0000) Subject: freebsd branch: swap plugin: Use `sysctlnametomib' to query the mib if we don't know it. X-Git-Tag: svn-trunk~2^2~2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c2318233f1e7656366019af4d79afb3e526011f8;p=collectd.git freebsd branch: swap plugin: Use `sysctlnametomib' to query the mib if we don't know it. Maybe this should be the default? --- diff --git a/src/swap.c b/src/swap.c index 7dd8d680..1d284f39 100644 --- a/src/swap.c +++ b/src/swap.c @@ -215,16 +215,29 @@ static void swap_read (void) /* #endif HAVE_LIBKSTAT */ #elif HAVE_SYS_SYSCTL_H - int mib[2]; + int mib[3]; + size_t mib_len; struct xsw_usage sw_usage; size_t sw_usage_len; + int status; - mib[0] = CTL_VM; - mib[1] = VM_SWAPUSAGE; +#if defined(VM_SWAPUSAGE) + mib_len = 2; + mib[0] = CTL_VM; + mib[1] = VM_SWAPUSAGE; +#else + mib_len = 3; + if ((status = sysctlnametomib ("vm.swap_info", mib, &mib_len)) < 0) + { + syslog (LOG_WARN, "swap plugin: sysctlnametomib failed: %s", + strerror (errno)); + return; + } +#endif sw_usage_len = sizeof (struct xsw_usage); - if (sysctl (mib, 2, &sw_usage, &sw_usage_len, NULL, 0) != 0) + if (sysctl (mib, mib_len, &sw_usage, &sw_usage_len, NULL, 0) != 0) return; /* The returned values are bytes. */