diff options
author | he <he@pkgsrc.org> | 2015-08-11 13:19:21 +0000 |
---|---|---|
committer | he <he@pkgsrc.org> | 2015-08-11 13:19:21 +0000 |
commit | d246fae9fc08243e33ab526910f3e8b98bcda4d7 (patch) | |
tree | a1f5347473564d3286e965549dea70dbf7314750 /sysutils | |
parent | c756ca39598c28fb3b00564fa5f14ee86dd897c7 (diff) | |
download | pkgsrc-d246fae9fc08243e33ab526910f3e8b98bcda4d7.tar.gz |
Port some of the plugins to support NetBSD:
* entropy
* memory
* swap
* disk
by shamelessly copying code from vmstat/iostat/rndctl etc.
Add comments to one patch missing one.
Bump PKGREVISION.
Diffstat (limited to 'sysutils')
-rw-r--r-- | sysutils/collectd/Makefile | 4 | ||||
-rw-r--r-- | sysutils/collectd/PLIST | 3 | ||||
-rw-r--r-- | sysutils/collectd/distinfo | 12 | ||||
-rw-r--r-- | sysutils/collectd/options.mk | 9 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-configure | 144 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-configure.ac | 66 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-src_config.h.in | 39 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-src_disk.c | 209 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-src_entropy.c | 87 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-src_memory.c | 117 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-src_swap.c | 148 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-src_tcpconns.c | 4 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-version-gen.sh | 14 |
13 files changed, 846 insertions, 10 deletions
diff --git a/sysutils/collectd/Makefile b/sysutils/collectd/Makefile index 60f66345f49..a911deb4c1a 100644 --- a/sysutils/collectd/Makefile +++ b/sysutils/collectd/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.6 2015/06/12 10:51:12 wiz Exp $ +# $NetBSD: Makefile,v 1.7 2015/08/11 13:19:21 he Exp $ -PKGREVISION= 1 +PKGREVISION= 2 .include "../../sysutils/collectd/Makefile.common" COMMENT= Statistics collection daemon base diff --git a/sysutils/collectd/PLIST b/sysutils/collectd/PLIST index d93d87b1fba..a9d79ab88fe 100644 --- a/sysutils/collectd/PLIST +++ b/sysutils/collectd/PLIST @@ -1,4 +1,4 @@ -@comment $NetBSD: PLIST,v 1.3 2015/04/14 11:27:30 fhajny Exp $ +@comment $NetBSD: PLIST,v 1.4 2015/08/11 13:19:21 he Exp $ bin/collectd-nagios bin/collectd-tg bin/collectdctl @@ -13,6 +13,7 @@ ${PLIST.battery}lib/collectd/battery.la ${PLIST.contextswitch}lib/collectd/contextswitch.la ${PLIST.cpu}lib/collectd/cpu.la lib/collectd/csv.la +${PLIST.entropy}lib/collectd/entropy.la ${PLIST.df}lib/collectd/df.la ${PLIST.disk}lib/collectd/disk.la lib/collectd/email.la diff --git a/sysutils/collectd/distinfo b/sysutils/collectd/distinfo index 6cfe8190dee..8fbbecb3dad 100644 --- a/sysutils/collectd/distinfo +++ b/sysutils/collectd/distinfo @@ -1,13 +1,21 @@ -$NetBSD: distinfo,v 1.8 2015/06/10 20:05:26 fhajny Exp $ +$NetBSD: distinfo,v 1.9 2015/08/11 13:19:21 he Exp $ SHA1 (collectd-5.5.0.tar.gz) = d24e284c1eae20c5e75b846c8b2612ab65bd5565 RMD160 (collectd-5.5.0.tar.gz) = 2197758942a5fe56e4eabda3786f09d4138e943a Size (collectd-5.5.0.tar.gz) = 2244454 bytes SHA1 (patch-Makefile.in) = 197307399312fa26c71ca168b92bbe41d31d556d +SHA1 (patch-configure) = d39d93002cd7b453122364824784c6b8c177724a +SHA1 (patch-configure.ac) = 5a9224941ccf0091108346d01714641da79f3f49 SHA1 (patch-src_Makefile.in) = f94d046ee323fdb9251ad49cf383b3a61df5dcaa SHA1 (patch-src_collectd-tg.c) = f9f41dfb0b1b55a62202128a165d5c9943faf5bc SHA1 (patch-src_collectd.conf.in) = f0b35085cf0ddfd766e140b145177ab1f1326f5f +SHA1 (patch-src_config.h.in) = 08765b041f4764873b4055140d85c4478faeba49 SHA1 (patch-src_df.c) = 19cca888b183a90759b359702e4d65c8afa6e58d +SHA1 (patch-src_disk.c) = 159862e8ca1e841e3c4013c03ba03f059fdbbab5 +SHA1 (patch-src_entropy.c) = 51551cb758115e5fd7f099e787cfa7758a5f1ea9 SHA1 (patch-src_libcollectclient_network__buffer.c) = e07d403d299613fa0885a0e7285849eb85510253 -SHA1 (patch-src_tcpconns.c) = fdc160087231a4aee2c405b8ed07791e90b20fd0 +SHA1 (patch-src_memory.c) = 7bbf24481e2ad6bb8b11a5e6bddd8145e1b2a6ef +SHA1 (patch-src_swap.c) = d7d214184db790bebfe70dfc5084a164c50f6892 +SHA1 (patch-src_tcpconns.c) = 712af1b821d62217283df884dd283d5b1218ab7c SHA1 (patch-src_utils__dns.c) = c3782dc9127f42da30e3142b853aa2cb2259af94 +SHA1 (patch-version-gen.sh) = 07d830019e22ac651514b75acf299b1f50c4632d diff --git a/sysutils/collectd/options.mk b/sysutils/collectd/options.mk index 8b3a7f0c120..a76c8eee029 100644 --- a/sysutils/collectd/options.mk +++ b/sysutils/collectd/options.mk @@ -1,12 +1,12 @@ -# $NetBSD: options.mk,v 1.2 2015/04/14 11:27:30 fhajny Exp $ +# $NetBSD: options.mk,v 1.3 2015/08/11 13:19:21 he Exp $ PKG_OPTIONS_VAR= PKG_OPTIONS.collectd PKG_SUPPORTED_OPTIONS= cpu df interface load memory syslog uptime PKG_SUGGESTED_OPTIONS+= cpu df interface load memory syslog uptime .if ${OPSYS} == "NetBSD" -PKG_SUPPORTED_OPTIONS+= contextswitch pf tcpconns users -PKG_SUGGESTED_OPTIONS+= contextswitch pf tcpconns users +PKG_SUPPORTED_OPTIONS+= contextswitch disk entropy pf swap tcpconns users +PKG_SUGGESTED_OPTIONS+= contextswitch disk entropy pf swap tcpconns users .endif .if ${OPSYS} == "FreeBSD" @@ -28,7 +28,8 @@ PKG_SUGGESTED_OPTIONS+= disk nfs swap users zfs-arc .include "../../mk/bsd.options.mk" -PLIST_VARS+= apple-sensors battery contextswitch cpu df disk \ +PLIST_VARS+= apple-sensors battery contextswitch cpu entropy \ + df disk \ interface load memory nfs pf processes swap \ syslog tcpconns uptime users zfs-arc diff --git a/sysutils/collectd/patches/patch-configure b/sysutils/collectd/patches/patch-configure new file mode 100644 index 00000000000..9f1251ff286 --- /dev/null +++ b/sysutils/collectd/patches/patch-configure @@ -0,0 +1,144 @@ +$NetBSD: patch-configure,v 1.3 2015/08/11 13:19:21 he Exp $ + +Regen from configure.ac. + +--- configure.orig 2015-05-27 07:51:50.000000000 +0000 ++++ configure +@@ -13908,7 +13908,7 @@ else + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) ++#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +@@ -13954,7 +13954,7 @@ else + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) ++#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +@@ -13978,7 +13978,7 @@ rm -f core conftest.err conftest.$ac_obj + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) ++#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +@@ -14023,7 +14023,7 @@ else + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) ++#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +@@ -14047,7 +14047,7 @@ rm -f core conftest.err conftest.$ac_obj + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) ++#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +@@ -15319,6 +15319,12 @@ $as_echo "#define KERNEL_OPENBSD 1" >>co + + ac_system="OpenBSD" + ;; ++ *netbsd*) ++ ++$as_echo "#define KERNEL_NETBSD 1" >>confdefs.h ++ ++ ac_system="NetBSD" ++ ;; + *aix*) + + $as_echo "#define KERNEL_AIX 1" >>confdefs.h +@@ -19171,6 +19177,54 @@ else + fi + + ++ac_fn_c_check_member "$LINENO" "struct kinfo_proc2" "p_pid" "ac_cv_member_struct_kinfo_proc2_p_pid" " ++#include <sys/param.h> ++#include <sys/sysctl.h> ++#include <kvm.h> ++ ++" ++if test "x$ac_cv_member_struct_kinfo_proc2_p_pid" = xyes; then : ++ ++cat >>confdefs.h <<_ACEOF ++#define HAVE_STRUCT_KINFO_PROC2_P_PID 1 ++_ACEOF ++ ++ ++ ++$as_echo "#define HAVE_STRUCT_KINFO_PROC_NETBSD 1" >>confdefs.h ++ ++ have_struct_kinfo_proc_netbsd="yes" ++ ++else ++ ++ have_struct_kinfo_proc_netbsd="no" ++ ++fi ++ac_fn_c_check_member "$LINENO" "struct kinfo_proc2" "p_uru_maxrss" "ac_cv_member_struct_kinfo_proc2_p_uru_maxrss" " ++#include <sys/param.h> ++#include <sys/sysctl.h> ++#include <kvm.h> ++ ++" ++if test "x$ac_cv_member_struct_kinfo_proc2_p_uru_maxrss" = xyes; then : ++ ++cat >>confdefs.h <<_ACEOF ++#define HAVE_STRUCT_KINFO_PROC2_P_URU_MAXRSS 1 ++_ACEOF ++ ++ ++ ++$as_echo "#define HAVE_STRUCT_KINFO_PROC_NETBSD 1" >>confdefs.h ++ ++ have_struct_kinfo_proc_netbsd="yes" ++ ++else ++ ++ have_struct_kinfo_proc_netbsd="no" ++ ++fi ++ ++ + ac_fn_c_check_member "$LINENO" "struct udphdr" "uh_dport" "ac_cv_member_struct_udphdr_uh_dport" "#define _BSD_SOURCE + #define _DEFAULT_SOURCE + #if HAVE_STDINT_H +@@ -27648,6 +27702,12 @@ then + plugin_tcpconns="yes" + fi + ++if test "x$ac_system" = "xNetBSD" ++then ++ plugin_entropy="yes" ++ plugin_disk="yes" ++fi ++ + # Mac OS X devices + if test "x$with_libiokit" = "xyes" + then +@@ -27890,6 +27950,11 @@ then + plugin_swap="yes" + fi + ++if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_three_args" = "xyes" ++then ++ plugin_swap="yes" ++fi ++ + if test "x$with_kvm_openfiles$with_kvm_nlist" = "xyesyes" + then + plugin_tcpconns="yes" diff --git a/sysutils/collectd/patches/patch-configure.ac b/sysutils/collectd/patches/patch-configure.ac new file mode 100644 index 00000000000..0f3530d542b --- /dev/null +++ b/sysutils/collectd/patches/patch-configure.ac @@ -0,0 +1,66 @@ +$NetBSD: patch-configure.ac,v 1.1 2015/08/11 13:19:21 he Exp $ + +Add KERNEL_NETBSD, add entry and disk plugins for NetBSD, +and also do swap for "have_swapctl_three_args" (as for NetBSD). +Also, the start of process support, but that's not yet finished. + +--- configure.ac.orig 2015-05-27 07:51:35.000000000 +0000 ++++ configure.ac +@@ -77,6 +77,10 @@ case $host_os in + AC_DEFINE([KERNEL_OPENBSD], 1, [True if program is to be compiled for an OpenBSD kernel]) + ac_system="OpenBSD" + ;; ++ *netbsd*) ++ AC_DEFINE([KERNEL_NETBSD], 1, [True if program is to be compiled for a NetBSD kernel]) ++ ac_system="NetBSD" ++ ;; + *aix*) + AC_DEFINE([KERNEL_AIX], 1, [True if program is to be compiled for a AIX kernel]) + ac_system="AIX" +@@ -1363,6 +1367,21 @@ AC_CHECK_MEMBERS([struct kinfo_proc.p_pi + #include <kvm.h> + ]) + ++AC_CHECK_MEMBERS([struct kinfo_proc2.p_pid, struct kinfo_proc2.p_uru_maxrss], ++ [ ++ AC_DEFINE(HAVE_STRUCT_KINFO_PROC_NETBSD, 1, ++ [Define if struct kinfo_proc2 exists in the NetBSD variant.]) ++ have_struct_kinfo_proc_netbsd="yes" ++ ], ++ [ ++ have_struct_kinfo_proc_netbsd="no" ++ ], ++ [ ++#include <sys/param.h> ++#include <sys/sysctl.h> ++#include <kvm.h> ++ ]) ++ + AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport], [], [], + [#define _BSD_SOURCE + #define _DEFAULT_SOURCE +@@ -5244,6 +5263,12 @@ then + plugin_tcpconns="yes" + fi + ++if test "x$ac_system" = "xNetBSD" ++then ++ plugin_entropy="yes" ++ plugin_disk="yes" ++fi ++ + # Mac OS X devices + if test "x$with_libiokit" = "xyes" + then +@@ -5482,6 +5507,11 @@ then + plugin_swap="yes" + fi + ++if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_three_args" = "xyes" ++then ++ plugin_swap="yes" ++fi ++ + if test "x$with_kvm_openfiles$with_kvm_nlist" = "xyesyes" + then + plugin_tcpconns="yes" diff --git a/sysutils/collectd/patches/patch-src_config.h.in b/sysutils/collectd/patches/patch-src_config.h.in new file mode 100644 index 00000000000..fe66e230f30 --- /dev/null +++ b/sysutils/collectd/patches/patch-src_config.h.in @@ -0,0 +1,39 @@ +$NetBSD: patch-src_config.h.in,v 1.1 2015/08/11 13:19:21 he Exp $ + +Optionally define a few vars for NetBSD. + +--- src/config.h.in.orig 2015-05-27 07:53:03.000000000 +0000 ++++ src/config.h.in +@@ -1246,6 +1246,12 @@ + /* Define to 1 if `imr_ifindex' is a member of `struct ip_mreqn'. */ + #undef HAVE_STRUCT_IP_MREQN_IMR_IFINDEX + ++/* Define to 1 if `p_pid' is a member of `struct kinfo_proc2'. */ ++#undef HAVE_STRUCT_KINFO_PROC2_P_PID ++ ++/* Define to 1 if `p_uru_maxrss' is a member of `struct kinfo_proc2'. */ ++#undef HAVE_STRUCT_KINFO_PROC2_P_URU_MAXRSS ++ + /* Define if struct kinfo_proc exists in the FreeBSD variant. */ + #undef HAVE_STRUCT_KINFO_PROC_FREEBSD + +@@ -1258,6 +1264,9 @@ + /* Define to 1 if `ki_rusage' is a member of `struct kinfo_proc'. */ + #undef HAVE_STRUCT_KINFO_PROC_KI_RUSAGE + ++/* Define if struct kinfo_proc2 exists in the NetBSD variant. */ ++#undef HAVE_STRUCT_KINFO_PROC_NETBSD ++ + /* Define if struct kinfo_proc exists in the OpenBSD variant. */ + #undef HAVE_STRUCT_KINFO_PROC_OPENBSD + +@@ -1507,6 +1516,9 @@ + /* True if program is to be compiled for a Linux kernel */ + #undef KERNEL_LINUX + ++/* True if program is to be compiled for a NetBSD kernel */ ++#undef KERNEL_NETBSD ++ + /* True if program is to be compiled for an OpenBSD kernel */ + #undef KERNEL_OPENBSD + diff --git a/sysutils/collectd/patches/patch-src_disk.c b/sysutils/collectd/patches/patch-src_disk.c new file mode 100644 index 00000000000..aabff0e4754 --- /dev/null +++ b/sysutils/collectd/patches/patch-src_disk.c @@ -0,0 +1,209 @@ +$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 2015-03-10 14:14:45.000000000 +0000 ++++ src/disk.c +@@ -124,6 +124,35 @@ static int numdisk; + static int pnumdisk; + /* #endif HAVE_PERFSTAT */ + ++#elif HAVE_SYSCTL && KERNEL_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; ++ ++/* #endif HAVE_SYSCTL && KERNEL_NETBSD */ ++ + #else + # error "No applicable input method." + #endif +@@ -241,7 +270,34 @@ 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; ++ ++ /* 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 */ +@@ -929,7 +985,129 @@ static int disk_read (void) + 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; ++ 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; ++ 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; ++ ++ /* 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 */ ++ 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]; ++ } ++ ++#endif /* HAVE_SYSCTL && KERNEL_NETBSD */ + + return (0); + } /* int disk_read */ diff --git a/sysutils/collectd/patches/patch-src_entropy.c b/sysutils/collectd/patches/patch-src_entropy.c new file mode 100644 index 00000000000..7512fa21fd0 --- /dev/null +++ b/sysutils/collectd/patches/patch-src_entropy.c @@ -0,0 +1,87 @@ +$NetBSD: patch-src_entropy.c,v 1.1 2015/08/11 13:19:21 he Exp $ + +Provide a NetBSD implementation for graphing available entropy. + +--- src/entropy.c.orig 2015-03-10 14:14:45.000000000 +0000 ++++ src/entropy.c +@@ -29,27 +29,43 @@ + #include "plugin.h" + + #if !KERNEL_LINUX +-# error "No applicable input method." +-#endif ++# if defined(__NetBSD__) ++/* Provide a NetBSD implementation, partial from rndctl.c */ + +-#define ENTROPY_FILE "/proc/sys/kernel/random/entropy_avail" ++#include <sys/types.h> ++#include <sys/ioctl.h> ++#include <sys/param.h> ++#include <sys/rnd.h> + +-static void entropy_submit (double entropy) ++static void entropy_submit (double); ++static int entropy_read (void); ++ ++static int ++entropy_read (void) + { +- value_t values[1]; +- value_list_t vl = VALUE_LIST_INIT; ++ rndpoolstat_t rs; ++ int fd; + +- values[0].gauge = entropy; ++ fd = open("/dev/urandom", O_RDONLY, 0644); ++ if (fd < 0) ++ return -1; + +- vl.values = values; +- vl.values_len = 1; +- sstrncpy (vl.host, hostname_g, sizeof (vl.host)); +- sstrncpy (vl.plugin, "entropy", sizeof (vl.plugin)); +- sstrncpy (vl.type, "entropy", sizeof (vl.type)); ++ if (ioctl(fd, RNDGETPOOLSTAT, &rs) < 0) ++ return -1; + +- plugin_dispatch_values (&vl); ++ entropy_submit (rs.curentropy); ++ ++ close(fd); ++ return 0; + } + ++# else /* not NetBSD */ ++# error "No applicable input method." ++# endif ++#else /* Linux */ ++ ++#define ENTROPY_FILE "/proc/sys/kernel/random/entropy_avail" ++ + static int entropy_read (void) + { + double entropy; +@@ -74,6 +90,23 @@ static int entropy_read (void) + + return (0); + } ++#endif /* not Linux */ ++ ++static void entropy_submit (double entropy) ++{ ++ value_t values[1]; ++ value_list_t vl = VALUE_LIST_INIT; ++ ++ values[0].gauge = entropy; ++ ++ vl.values = values; ++ vl.values_len = 1; ++ sstrncpy (vl.host, hostname_g, sizeof (vl.host)); ++ sstrncpy (vl.plugin, "entropy", sizeof (vl.plugin)); ++ sstrncpy (vl.type, "entropy", sizeof (vl.type)); ++ ++ plugin_dispatch_values (&vl); ++} + + void module_register (void) + { diff --git a/sysutils/collectd/patches/patch-src_memory.c b/sysutils/collectd/patches/patch-src_memory.c new file mode 100644 index 00000000000..742ee58aab5 --- /dev/null +++ b/sysutils/collectd/patches/patch-src_memory.c @@ -0,0 +1,117 @@ +$NetBSD: patch-src_memory.c,v 1.1 2015/08/11 13:19:21 he Exp $ + +Add a port for NetBSD using VM_UVMEXP2, and preferring +sysctl over sysctlbyname. + +--- src/memory.c.orig 2015-03-10 14:14:45.000000000 +0000 ++++ src/memory.c +@@ -65,6 +65,10 @@ static mach_port_t port_host; + static vm_size_t pagesize; + /* #endif HAVE_HOST_STATISTICS */ + ++#elif HAVE_SYSCTL ++static int pagesize; ++/* #endif HAVE_SYSCTL */ ++ + #elif HAVE_SYSCTLBYNAME + /* no global variables */ + /* #endif HAVE_SYSCTLBYNAME */ +@@ -78,10 +82,6 @@ static int pagesize; + static kstat_t *ksp; + /* #endif HAVE_LIBKSTAT */ + +-#elif HAVE_SYSCTL +-static int pagesize; +-/* #endif HAVE_SYSCTL */ +- + #elif HAVE_LIBSTATGRAB + /* no global variables */ + /* endif HAVE_LIBSTATGRAB */ +@@ -121,6 +121,15 @@ static int memory_init (void) + host_page_size (port_host, &pagesize); + /* #endif HAVE_HOST_STATISTICS */ + ++#elif HAVE_SYSCTL ++ pagesize = getpagesize (); ++ if (pagesize <= 0) ++ { ++ ERROR ("memory plugin: Invalid pagesize: %i", pagesize); ++ return (-1); ++ } ++/* #endif HAVE_SYSCTL */ ++ + #elif HAVE_SYSCTLBYNAME + /* no init stuff */ + /* #endif HAVE_SYSCTLBYNAME */ +@@ -139,15 +148,6 @@ static int memory_init (void) + } + /* #endif HAVE_LIBKSTAT */ + +-#elif HAVE_SYSCTL +- pagesize = getpagesize (); +- if (pagesize <= 0) +- { +- ERROR ("memory plugin: Invalid pagesize: %i", pagesize); +- return (-1); +- } +-/* #endif HAVE_SYSCTL */ +- + #elif HAVE_LIBSTATGRAB + /* no init stuff */ + /* #endif HAVE_LIBSTATGRAB */ +@@ -221,6 +221,46 @@ static int memory_read_internal (value_l + /* #endif HAVE_HOST_STATISTICS */ + + #elif HAVE_SYSCTLBYNAME ++ ++#if HAVE_SYSCTL && defined(KERNEL_NETBSD) ++ int mib[] = {CTL_VM, VM_UVMEXP2}; ++ struct uvmexp_sysctl uvmexp; ++ gauge_t mem_active; ++ gauge_t mem_inactive; ++ gauge_t mem_free; ++ gauge_t mem_wired; ++ gauge_t mem_kernel; ++ size_t size; ++ ++ memset (&uvmexp, 0, sizeof (uvmexp)); ++ size = sizeof (uvmexp); ++ ++ if (sysctl (mib, 2, &uvmexp, &size, NULL, 0) < 0) { ++ char errbuf[1024]; ++ WARNING ("memory plugin: sysctl failed: %s", ++ sstrerror (errno, errbuf, sizeof (errbuf))); ++ return (-1); ++ } ++ ++ assert (pagesize > 0); ++ mem_active = (gauge_t) (uvmexp.active * pagesize); ++ mem_inactive = (gauge_t) (uvmexp.inactive * pagesize); ++ mem_free = (gauge_t) (uvmexp.free * pagesize); ++ mem_wired = (gauge_t) (uvmexp.wired * pagesize); ++ mem_kernel = (gauge_t) ((uvmexp.npages - ( ++ uvmexp.active + uvmexp.inactive + ++ uvmexp.free + uvmexp.wired ++ )) * pagesize); ++ ++ MEMORY_SUBMIT ("active", mem_active, ++ "inactive", mem_inactive, ++ "free", mem_free, ++ "wired", mem_wired, ++ "kernel", mem_kernel); ++/* #endif HAVE_SYSCTL && defined(KERNEL_NETBSD) */ ++ ++#else /* Other HAVE_SYSCTLBYNAME providers */ ++ + /* + * vm.stats.vm.v_page_size: 4096 + * vm.stats.vm.v_page_count: 246178 +@@ -272,6 +312,8 @@ static int memory_read_internal (value_l + "active", (gauge_t) sysctl_vals[4], + "inactive", (gauge_t) sysctl_vals[5], + "cache", (gauge_t) sysctl_vals[6]); ++ ++#endif /* HAVE_SYSCTL && KERNEL_NETBSD */ + /* #endif HAVE_SYSCTLBYNAME */ + + #elif KERNEL_LINUX diff --git a/sysutils/collectd/patches/patch-src_swap.c b/sysutils/collectd/patches/patch-src_swap.c new file mode 100644 index 00000000000..af0b9f203d6 --- /dev/null +++ b/sysutils/collectd/patches/patch-src_swap.c @@ -0,0 +1,148 @@ +$NetBSD: patch-src_swap.c,v 1.1 2015/08/11 13:19:21 he Exp $ + +Extend support for NetBSD, and add per-swap-device +reporting for HAVE_SWAPCTL_THREE_ARGS. + +--- src/swap.c.orig 2015-05-20 12:04:47.000000000 +0000 ++++ src/swap.c +@@ -76,9 +76,10 @@ static _Bool report_bytes = 0; + static _Bool report_by_device = 0; + /* #endif KERNEL_LINUX */ + +-#elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS ++#elif HAVE_SWAPCTL && (HAVE_SWAPCTL_TWO_ARGS || HAVE_SWAPCTL_THREE_ARGS) + # define SWAP_HAVE_REPORT_BY_DEVICE 1 + static derive_t pagesize; ++static _Bool report_bytes = 0; + static _Bool report_by_device = 0; + /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */ + +@@ -114,7 +115,7 @@ static int swap_config (oconfig_item_t * + { + oconfig_item_t *child = ci->children + i; + if (strcasecmp ("ReportBytes", child->key) == 0) +-#if KERNEL_LINUX ++#if KERNEL_LINUX || KERNEL_NETBSD + cf_util_get_boolean (child, &report_bytes); + #else + WARNING ("swap plugin: The \"ReportBytes\" option " +@@ -147,7 +148,7 @@ static int swap_init (void) /* {{{ */ + pagesize = (derive_t) sysconf (_SC_PAGESIZE); + /* #endif KERNEL_LINUX */ + +-#elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS ++#elif HAVE_SWAPCTL && (HAVE_SWAPCTL_TWO_ARGS || HAVE_SWAPCTL_THREE_ARGS) + /* getpagesize(3C) tells me this does not fail.. */ + pagesize = (derive_t) getpagesize (); + /* #endif HAVE_SWAPCTL */ +@@ -213,7 +214,7 @@ static void swap_submit_usage (char cons + other_name, other_value, NULL); + } /* }}} void swap_submit_usage */ + +-#if KERNEL_LINUX || HAVE_PERFSTAT ++#if KERNEL_LINUX || HAVE_PERFSTAT || KERNEL_NETBSD + __attribute__((nonnull(1))) + static void swap_submit_derive (char const *type_instance, /* {{{ */ + derive_t value) +@@ -614,6 +615,43 @@ static int swap_read (void) /* {{{ */ + /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */ + + #elif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS ++#if KERNEL_NETBSD ++#include <uvm/uvm_extern.h> ++ ++static int ++swap_read_io (void) /* {{{ */ ++{ ++ static int uvmexp_mib[] = { CTL_VM, VM_UVMEXP2 }; ++ struct uvmexp_sysctl uvmexp; ++ size_t ssize; ++ derive_t swap_in, swap_out; ++ ++ ssize = sizeof(uvmexp); ++ memset(&uvmexp, 0, ssize); ++ if (sysctl(uvmexp_mib, __arraycount(uvmexp_mib), &uvmexp, ++ &ssize, NULL, 0) == -1) { ++ char errbuf[1024]; ++ WARNING ("swap: sysctl for uvmexp failed: %s", ++ sstrerror (errno, errbuf, sizeof (errbuf))); ++ return (-1); ++ } ++ ++ swap_in = uvmexp.pgswapin; ++ swap_out = uvmexp.pgswapout; ++ ++ if (report_bytes) ++ { ++ swap_in = swap_in * pagesize; ++ swap_out = swap_out * pagesize; ++ } ++ ++ swap_submit_derive ("in", swap_in); ++ swap_submit_derive ("out", swap_out); ++ ++ return (0); ++} /* }}} */ ++#endif ++ + static int swap_read (void) /* {{{ */ + { + struct swapent *swap_entries; +@@ -660,23 +698,53 @@ static int swap_read (void) /* {{{ */ + * swap_entries[i].se_path */ + for (i = 0; i < swap_num; i++) + { ++ char path[PATH_MAX]; ++ gauge_t this_used; ++ gauge_t this_total; ++ + if ((swap_entries[i].se_flags & SWF_ENABLE) == 0) + continue; + +- used += ((gauge_t) swap_entries[i].se_inuse) * C_SWAP_BLOCK_SIZE; +- total += ((gauge_t) swap_entries[i].se_nblks) * C_SWAP_BLOCK_SIZE; +- } ++ this_used = ((gauge_t) swap_entries[i].se_inuse) ++ * C_SWAP_BLOCK_SIZE; ++ this_total = ((gauge_t) swap_entries[i].se_nblks) ++ * C_SWAP_BLOCK_SIZE; ++ ++ ++ /* Shortcut for the "combined" setting (default) */ ++ if (!report_by_device) ++ { ++ used += this_used; ++ total += this_total; ++ continue; ++ } ++ ++ sstrncpy (path, swap_entries[i].se_path, sizeof (path)); ++ escape_slashes (path, sizeof (path)); ++ ++ swap_submit_usage (path, this_used, this_total - this_used, ++ NULL, NAN); ++ } /* for (swap_num) */ ++ + + if (total < used) + { + ERROR ("swap plugin: Total swap space (%g) is less than used swap space (%g).", + total, used); ++ sfree (swap_entries); + return (-1); + } + +- swap_submit_usage (NULL, used, total - used, NULL, NAN); ++ /* If the "separate" option was specified (report_by_device == 1), all ++ * values have already been dispatched from within the loop. */ ++ if (!report_by_device) ++ swap_submit_usage (NULL, used, total - used, NULL, NAN); + + sfree (swap_entries); ++ ++#if KERNEL_NETBSD ++ swap_read_io (); ++#endif + return (0); + } /* }}} int swap_read */ + /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS */ diff --git a/sysutils/collectd/patches/patch-src_tcpconns.c b/sysutils/collectd/patches/patch-src_tcpconns.c index 44a98d4a50d..409701700f2 100644 --- a/sysutils/collectd/patches/patch-src_tcpconns.c +++ b/sysutils/collectd/patches/patch-src_tcpconns.c @@ -1,4 +1,6 @@ -$NetBSD: patch-src_tcpconns.c,v 1.4 2015/06/10 20:05:26 fhajny Exp $ +$NetBSD: patch-src_tcpconns.c,v 1.5 2015/08/11 13:19:21 he Exp $ + +Include <sys/param.h> --- src/tcpconns.c.orig 2015-05-20 12:04:47.191035542 +0000 +++ src/tcpconns.c diff --git a/sysutils/collectd/patches/patch-version-gen.sh b/sysutils/collectd/patches/patch-version-gen.sh new file mode 100644 index 00000000000..6ca0cc93fd2 --- /dev/null +++ b/sysutils/collectd/patches/patch-version-gen.sh @@ -0,0 +1,14 @@ +$NetBSD: patch-version-gen.sh,v 1.1 2015/08/11 13:19:21 he Exp $ + +For work in pkgsrc, also strip '.git' suffix. + +--- version-gen.sh.orig 2015-05-26 20:23:28.000000000 +0000 ++++ version-gen.sh +@@ -8,6 +8,6 @@ if test -z "$VERSION"; then + VERSION="$DEFAULT_VERSION" + fi + +-VERSION="`echo \"$VERSION\" | sed -e 's/-/./g'`" ++VERSION="`echo \"$VERSION\" | sed -e 's/-/./g' | sed -e 's/.git//'`" + + printf "%s" "$VERSION" |