]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Implement NFS plugin for NetBSD
authorEdgar Fuß <ef@math.uni-bonn.de>
Thu, 31 Oct 2019 17:26:45 +0000 (18:26 +0100)
committerGitHub <noreply@github.com>
Thu, 31 Oct 2019 17:26:45 +0000 (18:26 +0100)
configure.ac
src/nfs.c

index 59a7f355c005cebcd81e7d15f828e4d1899a7c77..d5daa144b35aeca8b54c6844b8546420a356318f 100644 (file)
@@ -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
 
index 97d91259a338fae7973dfc9027cd7dc0e87a4b90..e8ae6408dfbe718fe85f3dd15163462823919613 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
 #include "plugin.h"
 #include "utils/common/common.h"
 
+#if KERNEL_NETBSD
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/sysctl.h>
+#include <nfs/rpcv2.h>
+#include <nfs/nfsproto.h>
+#include <nfs/nfs.h>
+#endif
+
 #if HAVE_KSTAT_H
 #include <kstat.h>
 #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) {