pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg/51334: collectd disk plugin NetBSD implementation correction



I wrote:
EF> Unfortunately, the old, non-functional disk plugin patch has been ported to the new collectd version (mainly formatting changes) instead of the functional one in the PR.

As it looks, my original PR contained the original, non-functional patch from pkgsrc instead of my one. So, for the record, here's my patch for 5.5.0 as it should have been in the original PR.
Sorry for the confusion.
$NetBSD: patch-src_disk.c,v 1.1 2015/08/11 13:19:21 he Exp $

Provide a port to NetBSD.

--- src/disk.c.orig	2016-07-11 11:40:37.000000000 +0200
+++ src/disk.c	2016-07-11 14:08:43.000000000 +0200
@@ -124,6 +124,16 @@
 static int pnumdisk;
 /* #endif HAVE_PERFSTAT */
 
+#elif HAVE_SYSCTL && KERNEL_NETBSD
+
+#include <sys/sysctl.h>
+#include <sys/iostat.h>
+
+static struct io_sysctl *drives = NULL;
+static size_t ndrive = 0;
+
+/* #endif HAVE_SYSCTL && KERNEL_NETBSD */
+
 #else
 # error "No applicable input method."
 #endif
@@ -241,7 +251,33 @@
 			continue;
 		ksp[numdisk++] = ksp_chain;
 	}
-#endif /* HAVE_LIBKSTAT */
+/* #endif HAVE_LIBKSTAT */
+
+#elif HAVE_SYSCTL && KERNEL_NETBSD
+	int mib[3];
+	size_t size;
+
+	/* figure out number of drives */
+	mib[0] = CTL_HW;
+	mib[1] = HW_IOSTATS;
+	mib[2] = sizeof(struct io_sysctl);
+	if (sysctl(mib, 3, NULL, &size, NULL, 0) == -1) {
+		ERROR ("disk plugin: sysctl for ndrives failed");
+		return -1;
+	}
+	ndrive = size / sizeof(struct io_sysctl);
+
+	if (size == 0 ) {
+		ERROR ("disk plugin: no drives found");
+		return -1;
+	}
+	drives = (struct io_sysctl *)malloc(size);
+	if (drives == NULL) {
+		ERROR ("disk plugin: memory allocation failure");
+		return -1;
+	}
+#endif	/* HAVE_SYSCTL && KERNEL_NETBSD */
+
 
 	return (0);
 } /* int disk_init */
@@ -291,7 +327,9 @@
 
 	plugin_dispatch_values (&vl);
 }
+#endif
 
+#if KERNEL_LINUX || (HAVE_SYSCTL && KERNEL_NETBSD)
 static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time)
 {
 	value_t values[2];
@@ -312,8 +350,10 @@
 
 	plugin_dispatch_values (&vl);
 }
+#endif
 
 
+#if KERNEL_LINUX
 static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops)
 {
 	double interval = CDTIME_T_TO_DOUBLE (plugin_get_interval ());
@@ -929,7 +969,57 @@
 		write_time *= ((double)(_system_configuration.Xint)/(double)(_system_configuration.Xfrac)) / 1000000.0;
 		disk_submit (stat_disk[i].name, "disk_time", read_time, write_time);
 	}
-#endif /* defined(HAVE_PERFSTAT) */
+/* #endif defined(HAVE_PERFSTAT) */
+
+#elif HAVE_SYSCTL && KERNEL_NETBSD
+	int mib[3];
+	size_t size, i, nndrive;
+
+	/* figure out number of drives */
+	mib[0] = CTL_HW;
+	mib[1] = HW_IOSTATS;
+	mib[2] = sizeof(struct io_sysctl);
+	if (sysctl(mib, 3, NULL, &size, NULL, 0) == -1) {
+		ERROR ("disk plugin: sysctl for ndrives failed");
+		return -1;
+	}
+	nndrive = size / sizeof(struct io_sysctl);
+
+	if (size == 0 ) {
+		ERROR ("disk plugin: no drives found");
+		return -1;
+	}
+	/* number of drives changed, reallocate buffer */
+	if (nndrive != ndrive) {
+		drives = (struct io_sysctl *)realloc(drives, size);
+		if (drives == NULL) {
+			ERROR ("disk plugin: memory allocation failure");
+			return -1;
+		}
+		ndrive = nndrive;
+	}
+
+	/* get stats for all drives */
+	mib[0] = CTL_HW;
+	mib[1] = HW_IOSTATS;
+	mib[2] = sizeof(struct io_sysctl);
+	if (sysctl(mib, 3, drives, &size, NULL, 0) == -1) {
+		ERROR ("disk plugin: sysctl for drive stats failed");
+		return -1;
+	}
+
+	for (i = 0; i < ndrive; i++) {
+		if (drives[i].type != IOSTAT_DISK)
+			continue;
+
+		disk_submit(drives[i].name, "disk_octets",
+		            drives[i].rbytes, drives[i].wbytes);
+		disk_submit(drives[i].name, "disk_ops",
+		            drives[i].rxfer, drives[i].wxfer);
+		submit_io_time(drives[i].name,
+		               drives[i].time_sec * 1000 + drives[i].time_usec / 1000, 0);
+	}
+#endif /* HAVE_SYSCTL && KERNEL_NETBSD */
 
 	return (0);
 } /* int disk_read */


Home | Main Index | Thread Index | Old Index