pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
collectd: correct disk plugin implementation for NetBSD
Module Name: pkgsrc-wip
Committed By: Edgar Fuß <ef%math.uni-bonn.de@localhost>
Pushed By: ef
Date: Fri Jul 17 18:37:44 2020 +0200
Changeset: 443439149dfba819610ff7187df90eed5f75fa00
Modified Files:
collectd/distinfo
collectd/patches/patch-src_disk.c
Log Message:
collectd: correct disk plugin implementation for NetBSD
Correct the disk plugin implementation for NetBSD in patch-src_disk.c.
The original author seems to have mis-understood the collect "derive" type. It doesn't mean the value provided is a derivative, but it's a gauge you're probably interested in the derivative of.
In fact, that makes the code a lot simpler.
See https://github.com/collectd/collectd/pull/3334 and https://github.com/collectd/collectd/pull/3379.
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=443439149dfba819610ff7187df90eed5f75fa00
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
collectd/distinfo | 3 +-
collectd/patches/patch-src_disk.c | 138 +++++++++-----------------------------
2 files changed, 34 insertions(+), 107 deletions(-)
diffs:
diff --git a/collectd/distinfo b/collectd/distinfo
index f1d1ceb6f4..2376ff1887 100644
--- a/collectd/distinfo
+++ b/collectd/distinfo
@@ -12,7 +12,7 @@ SHA1 (patch-src_cpu.c) = e645ae6b05c051c3c878f88a493fbbd7d548bb66
SHA1 (patch-src_daemon_collectd.c) = 155da2fde889e961719fe6be47aa7fc25199fbe7
SHA1 (patch-src_daemon_common.h) = d1ef6a5257156a864bf896629870f0f83a858cff
SHA1 (patch-src_df.c) = 5c6549cd9ec72efed5cdb7d8dd9297c50491426e
-SHA1 (patch-src_disk.c) = 6b51454f88ef728abd22cdae5fdd7a81289d502c
+SHA1 (patch-src_disk.c) = a9e71366f75fcc760384d41651771738ec28823f
SHA1 (patch-src_entropy.c) = f20ad4ce2e968ba0b20bb13aa00771fc424562fd
SHA1 (patch-src_irq.c) = 18106e9051ec344b0d45a23814eae5ba3be2f908
SHA1 (patch-src_libcollectclient_network__buffer.c) = a19e1658017279c35fd9860e2ab855081bad8327
@@ -20,6 +20,7 @@ SHA1 (patch-src_lua.c) = 656934889976f489abb80a8244492f845a3bd9f8
SHA1 (patch-src_memory.c) = 3276b09d0c09e0a9446519bd6c304d95c30b617a
SHA1 (patch-src_netstat__udp.c) = 30cb12d25f56c60959658dbd181783212e00cc61
SHA1 (patch-src_processes.c) = a22b1e9d7935c7924b65c57990b4212990acc6b7
+SHA1 (patch-src_read_kafka.c) = 05334bd0ea51ab386afce0cb3336378fcc42d997
SHA1 (patch-src_statsd.c) = 35f4349d2d2c9bddc0f4770344f969157cd012f6
SHA1 (patch-src_swap.c) = 98984dc7c6eee4f17b2f291124431172b06aa6c2
SHA1 (patch-src_tcpconns.c) = 0469ffe477ae96a79e4fd28c4428a1e7682e9461
diff --git a/collectd/patches/patch-src_disk.c b/collectd/patches/patch-src_disk.c
index 450b65dab4..a1bb5315f7 100644
--- a/collectd/patches/patch-src_disk.c
+++ b/collectd/patches/patch-src_disk.c
@@ -1,10 +1,10 @@
-$NetBSD: patch-src_disk.c,v 1.3 2017/11/21 15:18:23 fhajny Exp $
+$NetBSD: patch-src_disk.c,v $
-Provide a port to NetBSD.
+Provide a working port to NetBSD.
---- src/disk.c.orig 2017-11-18 09:03:27.354750373 +0000
-+++ src/disk.c
-@@ -135,6 +135,35 @@ static int numdisk;
+--- src/disk.c.orig 2018-08-30 15:04:48.000000000 +0200
++++ src/disk.c 2018-08-30 15:04:49.000000000 +0200
+@@ -135,6 +135,16 @@ static int numdisk;
static int pnumdisk;
/* #endif HAVE_PERFSTAT */
@@ -13,25 +13,6 @@ Provide a port to NetBSD.
+#include <sys/sysctl.h>
+#include <sys/iostat.h>
+
-+typedef struct diskstats {
-+ char *name;
-+
-+ u_int poll_count;
-+
-+ derive_t read_ops;
-+ derive_t write_ops;
-+
-+ derive_t read_bytes;
-+ derive_t write_bytes;
-+
-+ derive_t avg_io_time;
-+
-+ struct io_sysctl stats;
-+
-+ struct diskstats *next;
-+} diskstats_t;
-+
-+static diskstats_t *disklist;
+static struct io_sysctl *drives = NULL;
+static size_t ndrive = 0;
+
@@ -40,13 +21,12 @@ Provide a port to NetBSD.
#else
#error "No applicable input method."
#endif
-@@ -253,7 +282,33 @@ static int disk_init(void) {
+@@ -253,7 +263,31 @@ static int disk_init(void) {
continue;
ksp[numdisk++] = ksp_chain;
}
-#endif /* HAVE_LIBKSTAT */
+/* #endif HAVE_LIBKSTAT */
-+
+#elif HAVE_SYSCTL && KERNEL_NETBSD
+ int mib[3];
+ size_t size;
@@ -70,26 +50,37 @@ Provide a port to NetBSD.
+ ERROR ("disk plugin: memory allocation failure");
+ return -1;
+ }
-+
+#endif /* HAVE_SYSCTL && KERNEL_NETBSD */
return 0;
} /* int disk_init */
-@@ -1017,7 +1072,129 @@ static int disk_read(void) {
+@@ -284,7 +318,7 @@ static void disk_submit(const char *plug
+ plugin_dispatch_values(&vl);
+ } /* void disk_submit */
+
+-#if KERNEL_FREEBSD || KERNEL_LINUX
++#if KERNEL_FREEBSD || (HAVE_SYSCTL && KERNEL_NETBSD) || KERNEL_LINUX
+ static void submit_io_time(char const *plugin_instance, derive_t io_time,
+ derive_t weighted_time) {
+ value_list_t vl = VALUE_LIST_INIT;
+@@ -300,7 +334,7 @@ static void submit_io_time(char const *p
+
+ plugin_dispatch_values(&vl);
+ } /* void submit_io_time */
+-#endif /* KERNEL_FREEBSD || KERNEL_LINUX */
++#endif /* KERNEL_FREEBSD || (HAVE_SYSCTL && KERNEL_NETBSD) || KERNEL_LINUX */
+
+ #if KERNEL_LINUX
+ static void submit_in_progress(char const *disk_name, gauge_t in_progress) {
+@@ -1017,7 +1051,58 @@ static int disk_read(void) {
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;
-+ diskstats_t *ds, *pre_ds;
-+ char *output_name;
-+
-+ u_int64_t ops;
-+ u_int64_t delta_t;
+
+ /* figure out number of drives */
+ mib[0] = CTL_HW;
@@ -125,83 +116,18 @@ Provide a port to NetBSD.
+ }
+
+ for (i = 0; i < ndrive; i++) {
-+
+ if (drives[i].type != IOSTAT_DISK)
+ continue;
-+
-+ /* find drive stats, if present */
-+ for (ds = disklist, pre_ds = disklist;
-+ ds != NULL;
-+ pre_ds = ds, ds = ds->next) {
-+ if (strcmp (drives[i].name, ds->name) == 0)
-+ break;
-+ }
-+ if (ds == NULL) { /* not found; allocate & link in */
-+ if ((ds = calloc(1, sizeof(diskstats_t))) == NULL)
-+ continue;
-+ if ((ds->name = strdup(drives[i].name)) == NULL) {
-+ free(ds);
-+ continue;
-+ }
-+ if (pre_ds == NULL)
-+ disklist = ds;
-+ else
-+ pre_ds->next = ds;
-+ }
-+
-+ ds->poll_count++;
-+ if (ds->poll_count <= 2)
-+ {
-+ DEBUG ("disk plugin: (ds->poll_count = %i) <= "
-+ "(min_poll_count = 2); => Not writing.",
-+ ds->poll_count);
-+ ds->stats = drives[i]; /* but save base values */
++ if (ignorelist_match(ignorelist, drives[i].name))
+ continue;
-+ }
-+ ds->read_ops = drives[i].rxfer - ds->stats.rxfer;
-+ ds->write_ops = drives[i].wxfer - ds->stats.wxfer;
-+ ds->read_bytes = drives[i].rbytes - ds->stats.rbytes;
-+ ds->write_bytes = drives[i].wbytes - ds->stats.wbytes;
+
-+ /* Need this dance because of unsigned values... */
-+ if (drives[i].time_usec < ds->stats.time_usec) {
-+ delta_t = ((drives[i].time_sec - 1 -
-+ ds->stats.time_sec) * 1000) +
-+ ((drives[i].time_usec + 1000000 -
-+ ds->stats.time_usec) / 1000);
-+ } else {
-+ delta_t = ((drives[i].time_sec -
-+ ds->stats.time_sec) * 1000) +
-+ ((drives[i].time_usec -
-+ ds->stats.time_usec) / 1000);
-+ }
-+
-+ ops = ds->read_ops + ds->write_ops;
-+ if (ops == 0) {
-+ DEBUG ("disk plugin: read + write ops == 0, "
-+ "not writing");
-+ continue;
-+ }
-+
-+ ds->avg_io_time = delta_t / ops;
-+
-+ output_name = drives[i].name;
-+
-+ if ((ds->read_bytes != 0) || (ds->write_bytes != 0))
-+ disk_submit (output_name, "disk_octets",
-+ ds->read_bytes, ds->write_bytes);
-+
-+ if ((ds->read_ops != 0) || (ds->write_ops != 0))
-+ disk_submit (output_name, "disk_ops",
-+ ds->read_ops, ds->write_ops);
-+
-+ if (ds->avg_io_time != 0)
-+ disk_submit (output_name, "disk_time",
-+ ds->avg_io_time, ds->avg_io_time);
-+
-+ ds->stats = drives[i];
++ 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;
Home |
Main Index |
Thread Index |
Old Index