From 1900bc5037f6e4981659c3a407124a954065536b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Edgar=20Fu=C3=9F?= Date: Wed, 8 Jul 2020 19:10:22 +0200 Subject: [PATCH] Implement cpu plugin for NetBSD MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Implement the cpu plugin for NetBSD Written by HÃ¥vard Eidnes --- src/cpu.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/cpu.c b/src/cpu.c index 8c1d4cbd4..0e0a6e801 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -78,13 +78,16 @@ #endif #endif /* HAVE_SYS_DKSTAT_H */ -#define CAN_USE_SYSCTL 0 #if (defined(HAVE_SYSCTL) && defined(HAVE_SYSCTLBYNAME)) || defined(__OpenBSD__) /* Implies BSD variant */ #if defined(CTL_HW) && defined(HW_NCPU) && defined(CTL_KERN) && \ - defined(KERN_CPTIME) && defined(CPUSTATES) + (defined(KERN_CPTIME) || defined(KERN_CP_TIME)) && defined(CPUSTATES) #define CAN_USE_SYSCTL 1 +#else +#define CAN_USE_SYSCTL 0 #endif +#else +#define CAN_USE_SYSCTL 0 #endif /* HAVE_SYSCTL_H && HAVE_SYSCTLBYNAME || __OpenBSD__ */ #define COLLECTD_CPU_STATE_USER 0 @@ -746,6 +749,24 @@ static int cpu_read(void) { memset(cpuinfo, 0, sizeof(cpuinfo)); +#if defined(KERN_CP_TIME) && defined(KERNEL_NETBSD) + { + int mib[] = {CTL_KERN, KERN_CP_TIME}; + + cpuinfo_size = sizeof(cpuinfo[0]) * numcpu * CPUSTATES; + status = sysctl(mib, 2, cpuinfo, &cpuinfo_size, NULL, 0); + if (status == -1) { + char errbuf[1024]; + + ERROR ("cpu plugin: sysctl failed: %s.", + sstrerror (errno, errbuf, sizeof (errbuf))); + return -1; + } + if (cpuinfo_size == (sizeof(cpuinfo[0]) * CPUSTATES)) { + numcpu = 1; + } + } +#else /* defined(KERN_CP_TIME) && defined(KERNEL_NETBSD) */ #if defined(KERN_CPTIME2) if (numcpu > 1) { for (int i = 0; i < numcpu; i++) { @@ -779,6 +800,7 @@ static int cpu_read(void) { cpuinfo[0][i] = cpuinfo_tmp[i]; } } +#endif /* defined(KERN_CP_TIME) && defined(KERNEL_NETBSD) */ for (int i = 0; i < numcpu; i++) { cpu_stage(i, COLLECTD_CPU_STATE_USER, (derive_t)cpuinfo[i][CP_USER], now); -- 2.47.2