From 876e6792095f97704f7e0639960d53483ab493cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Edgar=20Fu=C3=9F?= Date: Thu, 31 Oct 2019 18:26:45 +0100 Subject: [PATCH] Implement NFS plugin for NetBSD --- configure.ac | 1 + src/nfs.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 59a7f355c..d5daa144b 100644 --- a/configure.ac +++ b/configure.ac @@ -6450,6 +6450,7 @@ if test "x$ac_system" = "xNetBSD"; then plugin_disk="yes" plugin_entropy="yes" plugin_irq="yes" + plugin_nfs="yes" plugin_processes="yes" fi diff --git a/src/nfs.c b/src/nfs.c index 97d91259a..e8ae6408d 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -27,6 +27,15 @@ #include "plugin.h" #include "utils/common/common.h" +#if KERNEL_NETBSD +#include +#include +#include +#include +#include +#include +#endif + #if HAVE_KSTAT_H #include #endif @@ -82,12 +91,14 @@ Number Procedures Procedures 21 commit */ +#if KERNEL_LINUX | HAVE_KSTAT static const char *nfs2_procedures_names[] = { "null", "getattr", "setattr", "root", "lookup", "readlink", "read", "wrcache", "write", "create", "remove", "rename", "link", "symlink", "mkdir", "rmdir", "readdir", "fsstat"}; static size_t nfs2_procedures_names_num = STATIC_ARRAY_SIZE(nfs2_procedures_names); +#endif static const char *nfs3_procedures_names[] = { "null", "getattr", "setattr", "lookup", "access", "readlink", @@ -320,7 +331,7 @@ static int nfs_config(const char *key, const char *value) { return 0; } -#if KERNEL_LINUX +#if KERNEL_LINUX || KERNEL_NETBSD static int nfs_init(void) { return 0; } /* #endif KERNEL_LINUX */ @@ -596,6 +607,28 @@ static int nfs_read(void) { } /* #endif KERNEL_LINUX */ +#elif KERNEL_NETBSD +static int nfs_read(void) { + struct nfsstats ns; + size_t size = sizeof(ns); + int mib[] = { CTL_VFS, 2, NFS_NFSSTATS }; + value_t values[nfs3_procedures_names_num]; + int i; + + /* NetBSD reports v2 statistics mapped to v3 and doen't yet support v4 */ + if (!report_v3) return 0; + if (sysctl(mib, 3, &ns, &size, NULL, 0) != 0) return 1; + + for (i = 0; i < nfs3_procedures_names_num; i++) values[i].counter = (derive_t)ns.rpccnt[i]; + nfs_procedures_submit("v3client", nfs3_procedures_names, values, nfs3_procedures_names_num); + + for (i = 0; i < nfs3_procedures_names_num; i++) values[i].counter = (derive_t)ns.srvrpccnt[i]; + nfs_procedures_submit("v3server", nfs3_procedures_names, values, nfs3_procedures_names_num); + + return 0; +} +/* #endif KERNEL_NETBSD */ + #elif HAVE_LIBKSTAT static int nfs_read(void) { if (report_v2) { -- 2.47.2