Improve upon previous patch (fix to use sysctls instead of KVM to
retrieve CPU stats). Use the newer BSD sysctl code already available in the 5.4.x instead of re-enabling the obsolete code from the previous release.
This commit is contained in:
parent
81fcb47638
commit
6498cb6bd6
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=213019
10 changed files with 226 additions and 78 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
PORTNAME= snmp
|
||||
PORTVERSION= 5.4.1
|
||||
PORTREVISION= 3
|
||||
PORTREVISION= 4
|
||||
CATEGORIES= net-mgmt ipv6
|
||||
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
|
||||
MASTER_SITE_SUBDIR= net-snmp
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
$FreeBSD$
|
||||
|
||||
--- agent/mibgroup/hardware/cpu.h
|
||||
+++ agent/mibgroup/hardware/cpu.h
|
||||
@@ -12,10 +12,10 @@
|
||||
#elif defined(irix6)
|
||||
config_require(hardware/cpu/cpu_sysinfo)
|
||||
|
||||
-#elif (defined(netbsd) || defined(netbsd1) || defined(netbsdelf) || defined(netbsdelf2)|| defined(netbsdelf3) || defined(openbsd2)|| defined(openbsd3) || defined(openbsd4))
|
||||
+#elif (defined(netbsd) || defined(netbsd1) || defined(netbsdelf) || defined(netbsdelf2)|| defined(netbsdelf3) || defined(openbsd2)|| defined(openbsd3) || defined(openbsd4) || defined(freebsd4) || defined(freebsd5)|| defined(freebsd6))
|
||||
config_require(hardware/cpu/cpu_sysctl)
|
||||
|
||||
-#elif (defined(freebsd2) || defined(freebsd3) || defined(freebsd4) || defined(freebsd5)|| defined(freebsd6))
|
||||
+#elif (defined(freebsd2) || defined(freebsd3))
|
||||
config_require(hardware/cpu/cpu_nlist)
|
||||
|
||||
#elif (defined(aix4) || defined(aix5))
|
|
@ -0,0 +1,94 @@
|
|||
|
||||
$FreeBSD$
|
||||
|
||||
--- agent/mibgroup/hardware/cpu/cpu_sysctl.c.orig
|
||||
+++ agent/mibgroup/hardware/cpu/cpu_sysctl.c
|
||||
@@ -11,7 +11,14 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
+#if defined(__FreeBSD__)
|
||||
+#include <sys/resource.h>
|
||||
+#if !defined(CPUSTATES)
|
||||
+#include <sys/dkstat.h>
|
||||
+#endif
|
||||
+#else
|
||||
#include <sys/sched.h>
|
||||
+#endif
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/vmmeter.h>
|
||||
@@ -37,11 +44,11 @@
|
||||
strcpy(cpu->name, "Overall CPU statistics");
|
||||
|
||||
i = sizeof(n);
|
||||
- sysctl(ncpu_mib, 2, &n, &i, NULL, 0);
|
||||
+ sysctl(ncpu_mib, 2, &n, (void *)&i, NULL, 0);
|
||||
if ( n <= 0 )
|
||||
n = 1; /* Single CPU system */
|
||||
i = sizeof(descr);
|
||||
- sysctl(model_mib, 2, descr, &i, NULL, 0);
|
||||
+ sysctl(model_mib, 2, descr, (void *)&i, NULL, 0);
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
cpu = netsnmp_cpu_get_byIdx( i, 1 );
|
||||
cpu->status = 2; /* running */
|
||||
@@ -64,6 +71,8 @@
|
||||
#undef NETSNMP_CPU_STATS
|
||||
#define NETSNMP_CPU_STATS uint64_t
|
||||
#endif
|
||||
+#elif defined(__FreeBSD__)
|
||||
+#define NETSNMP_KERN_CPU 0 /* FreeBSD - dummy value, sysctlnametomib(2) should be used */
|
||||
#else
|
||||
#error "No CPU statistics sysctl token"
|
||||
#endif
|
||||
@@ -95,7 +104,7 @@
|
||||
#define NETSNMP_VM_STATS_TYPE struct uvmexp
|
||||
#endif /* VM_UVMEXP2 || VM_UVMEXP */
|
||||
|
||||
-#elif defined(VM_METER) /* OpenBSD, NetBSD, FreeBSD */
|
||||
+#elif defined(VM_METER) && !defined(__FreeBSD__) /* OpenBSD, NetBSD */
|
||||
#define NETSNMP_VM_STATS VM_METER
|
||||
#define NETSNMP_VM_STATS_TYPE struct vmtotal
|
||||
|
||||
@@ -108,6 +117,15 @@
|
||||
#undef NS_VM_PAGEOUT
|
||||
#define NS_VM_SWAPIN v_swpin
|
||||
#define NS_VM_SWAPOUT v_swpout
|
||||
+#elif defined(__FreeBSD__) /* FreeBSD */
|
||||
+#define NETSNMP_VM_STATS VM_METER
|
||||
+#define NETSNMP_VM_STATS_TYPE struct vmmeter
|
||||
+ #define NS_VM_INTR v_intr
|
||||
+ #define NS_VM_SWTCH v_swtch
|
||||
+ #define NS_VM_PAGEIN v_swappgsin
|
||||
+ #define NS_VM_PAGEOUT v_swappgsout
|
||||
+ #define NS_VM_SWAPIN v_swapin
|
||||
+ #define NS_VM_SWAPOUT v_swapout
|
||||
#endif
|
||||
|
||||
|
||||
@@ -126,7 +144,7 @@
|
||||
*/
|
||||
NETSNMP_CPU_STATS cpu_stats[CPUSTATES];
|
||||
int cpu_mib[] = { CTL_KERN, NETSNMP_KERN_CPU };
|
||||
- int cpu_size = sizeof(cpu_stats);
|
||||
+ size_t cpu_size = sizeof(cpu_stats);
|
||||
#ifdef NETSNMP_KERN_MCPU
|
||||
NETSNMP_KERN_MCPU_TYPE *mcpu_stats;
|
||||
int mcpu_mib[] = { CTL_KERN, NETSNMP_KERN_MCPU };
|
||||
@@ -134,10 +152,13 @@
|
||||
#endif
|
||||
NETSNMP_VM_STATS_TYPE mem_stats;
|
||||
int mem_mib[] = { CTL_VM, NETSNMP_VM_STATS };
|
||||
- int mem_size = sizeof(NETSNMP_VM_STATS_TYPE);
|
||||
+ size_t mem_size = sizeof(NETSNMP_VM_STATS_TYPE);
|
||||
netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 0 );
|
||||
-
|
||||
- sysctl(cpu_mib, 2, cpu_stats, &cpu_size, NULL, 0);
|
||||
+#if defined(__FreeBSD__)
|
||||
+ sysctlbyname("kern.cp_time", cpu_stats, &cpu_size, NULL, 0);
|
||||
+#else
|
||||
+ sysctl(cpu_time, 2, cpu_stats, &cpu_size, NULL, 0);
|
||||
+#endif
|
||||
cpu->user_ticks = (unsigned long)cpu_stats[CP_USER];
|
||||
cpu->nice_ticks = (unsigned long)cpu_stats[CP_NICE];
|
||||
cpu->sys2_ticks = (unsigned long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR];
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
$FreeBSD$
|
||||
|
||||
--- agent/mibgroup/ucd_snmp.h.orig
|
||||
+++ agent/mibgroup/ucd_snmp.h
|
||||
@@ -13,5 +13,10 @@
|
||||
config_require(ucd-snmp/logmatch)
|
||||
config_require(ucd-snmp/memory)
|
||||
config_require(ucd-snmp/vmstat)
|
||||
+config_arch_require(freebsd4, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd5, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd6, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd7, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd8, ucd-snmp/vmstat_freebsd2)
|
||||
config_add_mib(UCD-SNMP-MIB)
|
||||
config_add_mib(UCD-DEMO-MIB)
|
|
@ -1,22 +0,0 @@
|
|||
--- agent/mibgroup/ucd-snmp/vmstat_freebsd2.c.orig 2008-04-25 16:28:53.000000000 +0300
|
||||
+++ agent/mibgroup/ucd-snmp/vmstat_freebsd2.c 2008-04-25 16:29:01.000000000 +0300
|
||||
@@ -174,6 +174,7 @@
|
||||
static long cpu_total;
|
||||
long cpu_sum;
|
||||
double cpu_prc;
|
||||
+ int mib[2], mib_len, cpu_new_len;
|
||||
|
||||
static struct vmmeter mem_old, mem_new;
|
||||
|
||||
@@ -195,7 +196,10 @@
|
||||
/*
|
||||
* CPU usage
|
||||
*/
|
||||
- auto_nlist(CPTIME_SYMBOL, (char *) cpu_new, sizeof(cpu_new));
|
||||
+ mib_len = 2;
|
||||
+ sysctlnametomib("kern.cp_time", mib, &mib_len);
|
||||
+ cpu_new_len = sizeof(cpu_new);
|
||||
+ sysctl(mib, mib_len, cpu_new, &cpu_new_len, NULL, 0);
|
||||
|
||||
cpu_total = 0;
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
PORTNAME= snmp
|
||||
PORTVERSION= 5.4.1
|
||||
PORTREVISION= 3
|
||||
PORTREVISION= 4
|
||||
CATEGORIES= net-mgmt ipv6
|
||||
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
|
||||
MASTER_SITE_SUBDIR= net-snmp
|
||||
|
|
18
net-mgmt/net-snmp/files/patch-agent_mibgroup_hardware_cpu.h
Normal file
18
net-mgmt/net-snmp/files/patch-agent_mibgroup_hardware_cpu.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
$FreeBSD$
|
||||
|
||||
--- agent/mibgroup/hardware/cpu.h
|
||||
+++ agent/mibgroup/hardware/cpu.h
|
||||
@@ -12,10 +12,10 @@
|
||||
#elif defined(irix6)
|
||||
config_require(hardware/cpu/cpu_sysinfo)
|
||||
|
||||
-#elif (defined(netbsd) || defined(netbsd1) || defined(netbsdelf) || defined(netbsdelf2)|| defined(netbsdelf3) || defined(openbsd2)|| defined(openbsd3) || defined(openbsd4))
|
||||
+#elif (defined(netbsd) || defined(netbsd1) || defined(netbsdelf) || defined(netbsdelf2)|| defined(netbsdelf3) || defined(openbsd2)|| defined(openbsd3) || defined(openbsd4) || defined(freebsd4) || defined(freebsd5)|| defined(freebsd6))
|
||||
config_require(hardware/cpu/cpu_sysctl)
|
||||
|
||||
-#elif (defined(freebsd2) || defined(freebsd3) || defined(freebsd4) || defined(freebsd5)|| defined(freebsd6))
|
||||
+#elif (defined(freebsd2) || defined(freebsd3))
|
||||
config_require(hardware/cpu/cpu_nlist)
|
||||
|
||||
#elif (defined(aix4) || defined(aix5))
|
|
@ -0,0 +1,94 @@
|
|||
|
||||
$FreeBSD$
|
||||
|
||||
--- agent/mibgroup/hardware/cpu/cpu_sysctl.c.orig
|
||||
+++ agent/mibgroup/hardware/cpu/cpu_sysctl.c
|
||||
@@ -11,7 +11,14 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
+#if defined(__FreeBSD__)
|
||||
+#include <sys/resource.h>
|
||||
+#if !defined(CPUSTATES)
|
||||
+#include <sys/dkstat.h>
|
||||
+#endif
|
||||
+#else
|
||||
#include <sys/sched.h>
|
||||
+#endif
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/vmmeter.h>
|
||||
@@ -37,11 +44,11 @@
|
||||
strcpy(cpu->name, "Overall CPU statistics");
|
||||
|
||||
i = sizeof(n);
|
||||
- sysctl(ncpu_mib, 2, &n, &i, NULL, 0);
|
||||
+ sysctl(ncpu_mib, 2, &n, (void *)&i, NULL, 0);
|
||||
if ( n <= 0 )
|
||||
n = 1; /* Single CPU system */
|
||||
i = sizeof(descr);
|
||||
- sysctl(model_mib, 2, descr, &i, NULL, 0);
|
||||
+ sysctl(model_mib, 2, descr, (void *)&i, NULL, 0);
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
cpu = netsnmp_cpu_get_byIdx( i, 1 );
|
||||
cpu->status = 2; /* running */
|
||||
@@ -64,6 +71,8 @@
|
||||
#undef NETSNMP_CPU_STATS
|
||||
#define NETSNMP_CPU_STATS uint64_t
|
||||
#endif
|
||||
+#elif defined(__FreeBSD__)
|
||||
+#define NETSNMP_KERN_CPU 0 /* FreeBSD - dummy value, sysctlnametomib(2) should be used */
|
||||
#else
|
||||
#error "No CPU statistics sysctl token"
|
||||
#endif
|
||||
@@ -95,7 +104,7 @@
|
||||
#define NETSNMP_VM_STATS_TYPE struct uvmexp
|
||||
#endif /* VM_UVMEXP2 || VM_UVMEXP */
|
||||
|
||||
-#elif defined(VM_METER) /* OpenBSD, NetBSD, FreeBSD */
|
||||
+#elif defined(VM_METER) && !defined(__FreeBSD__) /* OpenBSD, NetBSD */
|
||||
#define NETSNMP_VM_STATS VM_METER
|
||||
#define NETSNMP_VM_STATS_TYPE struct vmtotal
|
||||
|
||||
@@ -108,6 +117,15 @@
|
||||
#undef NS_VM_PAGEOUT
|
||||
#define NS_VM_SWAPIN v_swpin
|
||||
#define NS_VM_SWAPOUT v_swpout
|
||||
+#elif defined(__FreeBSD__) /* FreeBSD */
|
||||
+#define NETSNMP_VM_STATS VM_METER
|
||||
+#define NETSNMP_VM_STATS_TYPE struct vmmeter
|
||||
+ #define NS_VM_INTR v_intr
|
||||
+ #define NS_VM_SWTCH v_swtch
|
||||
+ #define NS_VM_PAGEIN v_swappgsin
|
||||
+ #define NS_VM_PAGEOUT v_swappgsout
|
||||
+ #define NS_VM_SWAPIN v_swapin
|
||||
+ #define NS_VM_SWAPOUT v_swapout
|
||||
#endif
|
||||
|
||||
|
||||
@@ -126,7 +144,7 @@
|
||||
*/
|
||||
NETSNMP_CPU_STATS cpu_stats[CPUSTATES];
|
||||
int cpu_mib[] = { CTL_KERN, NETSNMP_KERN_CPU };
|
||||
- int cpu_size = sizeof(cpu_stats);
|
||||
+ size_t cpu_size = sizeof(cpu_stats);
|
||||
#ifdef NETSNMP_KERN_MCPU
|
||||
NETSNMP_KERN_MCPU_TYPE *mcpu_stats;
|
||||
int mcpu_mib[] = { CTL_KERN, NETSNMP_KERN_MCPU };
|
||||
@@ -134,10 +152,13 @@
|
||||
#endif
|
||||
NETSNMP_VM_STATS_TYPE mem_stats;
|
||||
int mem_mib[] = { CTL_VM, NETSNMP_VM_STATS };
|
||||
- int mem_size = sizeof(NETSNMP_VM_STATS_TYPE);
|
||||
+ size_t mem_size = sizeof(NETSNMP_VM_STATS_TYPE);
|
||||
netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 0 );
|
||||
-
|
||||
- sysctl(cpu_mib, 2, cpu_stats, &cpu_size, NULL, 0);
|
||||
+#if defined(__FreeBSD__)
|
||||
+ sysctlbyname("kern.cp_time", cpu_stats, &cpu_size, NULL, 0);
|
||||
+#else
|
||||
+ sysctl(cpu_time, 2, cpu_stats, &cpu_size, NULL, 0);
|
||||
+#endif
|
||||
cpu->user_ticks = (unsigned long)cpu_stats[CP_USER];
|
||||
cpu->nice_ticks = (unsigned long)cpu_stats[CP_NICE];
|
||||
cpu->sys2_ticks = (unsigned long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR];
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
$FreeBSD$
|
||||
|
||||
--- agent/mibgroup/ucd_snmp.h.orig
|
||||
+++ agent/mibgroup/ucd_snmp.h
|
||||
@@ -13,5 +13,10 @@
|
||||
config_require(ucd-snmp/logmatch)
|
||||
config_require(ucd-snmp/memory)
|
||||
config_require(ucd-snmp/vmstat)
|
||||
+config_arch_require(freebsd4, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd5, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd6, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd7, ucd-snmp/vmstat_freebsd2)
|
||||
+config_arch_require(freebsd8, ucd-snmp/vmstat_freebsd2)
|
||||
config_add_mib(UCD-SNMP-MIB)
|
||||
config_add_mib(UCD-DEMO-MIB)
|
|
@ -1,22 +0,0 @@
|
|||
--- agent/mibgroup/ucd-snmp/vmstat_freebsd2.c.orig 2008-04-25 16:28:53.000000000 +0300
|
||||
+++ agent/mibgroup/ucd-snmp/vmstat_freebsd2.c 2008-04-25 16:29:01.000000000 +0300
|
||||
@@ -174,6 +174,7 @@
|
||||
static long cpu_total;
|
||||
long cpu_sum;
|
||||
double cpu_prc;
|
||||
+ int mib[2], mib_len, cpu_new_len;
|
||||
|
||||
static struct vmmeter mem_old, mem_new;
|
||||
|
||||
@@ -195,7 +196,10 @@
|
||||
/*
|
||||
* CPU usage
|
||||
*/
|
||||
- auto_nlist(CPTIME_SYMBOL, (char *) cpu_new, sizeof(cpu_new));
|
||||
+ mib_len = 2;
|
||||
+ sysctlnametomib("kern.cp_time", mib, &mib_len);
|
||||
+ cpu_new_len = sizeof(cpu_new);
|
||||
+ sysctl(mib, mib_len, cpu_new, &cpu_new_len, NULL, 0);
|
||||
|
||||
cpu_total = 0;
|
||||
|
Loading…
Reference in a new issue