Fri Apr 5 01:02:22 2013 UTC ()
add per cpu loads


(christos)
diff -r1.2 -r1.3 pkgsrc/net/net-snmp/patches/patch-agent_mibgroup_hardware_cpu_cpu__sysctl.c

cvs diff -r1.2 -r1.3 pkgsrc/net/net-snmp/patches/patch-agent_mibgroup_hardware_cpu_cpu__sysctl.c (expand / switch to unified diff)

--- pkgsrc/net/net-snmp/patches/patch-agent_mibgroup_hardware_cpu_cpu__sysctl.c 2013/04/04 19:59:06 1.2
+++ pkgsrc/net/net-snmp/patches/patch-agent_mibgroup_hardware_cpu_cpu__sysctl.c 2013/04/05 01:02:22 1.3
@@ -1,17 +1,17 @@ @@ -1,17 +1,17 @@
1$NetBSD: patch-agent_mibgroup_hardware_cpu_cpu__sysctl.c,v 1.2 2013/04/04 19:59:06 christos Exp $ 1$NetBSD: patch-agent_mibgroup_hardware_cpu_cpu__sysctl.c,v 1.3 2013/04/05 01:02:22 christos Exp $
2 2
3--- agent/mibgroup/hardware/cpu/cpu_sysctl.c.orig 2012-10-09 18:28:58.000000000 -0400 3--- agent/mibgrpu/hardware/cpu/cpu_sysctl.c.orig 2012-10-09 18:28:58.000000000 -0400
4+++ agent/mibgroup/hardware/cpu/cpu_sysctl.c 2013-04-04 15:33:49.000000000 -0400 4+++ agent/mibgrpu/hardware/cpu/cpu_sysctl.c 2013-04-04 20:55:47.000000000 -0400
5@@ -10,6 +10,7 @@ 5@@ -10,6 +10,7 @@
6  6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <unistd.h> 8 #include <unistd.h>
9+#include <errno.h> 9+#include <errno.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
11  11
12 #if defined(__FreeBSD__) 12 #if defined(__FreeBSD__)
13@@ -24,6 +25,9 @@ 13@@ -24,6 +25,9 @@
14 #include <sys/param.h> 14 #include <sys/param.h>
15 #include <sys/sysctl.h> 15 #include <sys/sysctl.h>
16 #include <sys/vmmeter.h> 16 #include <sys/vmmeter.h>
17+#ifdef HAVE_UVM_UVM_EXTERN_H 17+#ifdef HAVE_UVM_UVM_EXTERN_H
@@ -65,23 +65,52 @@ $NetBSD: patch-agent_mibgroup_hardware_c @@ -65,23 +65,52 @@ $NetBSD: patch-agent_mibgroup_hardware_c
65 #endif 65 #endif
66 cpu->user_ticks = (unsigned long long)cpu_stats[CP_USER]; 66 cpu->user_ticks = (unsigned long long)cpu_stats[CP_USER];
67 cpu->nice_ticks = (unsigned long long)cpu_stats[CP_NICE]; 67 cpu->nice_ticks = (unsigned long long)cpu_stats[CP_NICE];
68@@ -190,7 +199,8 @@ 68@@ -190,7 +199,8 @@
69 * Interrupt/Context Switch statistics 69 * Interrupt/Context Switch statistics
70 * XXX - Do these really belong here ? 70 * XXX - Do these really belong here ?
71 */ 71 */
72- sysctl(mem_mib, 2, &mem_stats, &mem_size, NULL, 0); 72- sysctl(mem_mib, 2, &mem_stats, &mem_size, NULL, 0);
73+ if (sysctl(mem_mib, 2, &mem_stats, &mem_size, NULL, 0) == -1) 73+ if (sysctl(mem_mib, 2, &mem_stats, &mem_size, NULL, 0) == -1)
74+ snmp_log(LOG_ERR, "sysctl vm.vm_meter failed (errno %d)\n", errno); 74+ snmp_log(LOG_ERR, "sysctl vm.vm_meter failed (errno %d)\n", errno);
75 cpu->nInterrupts = (unsigned long long)mem_stats.NS_VM_INTR; 75 cpu->nInterrupts = (unsigned long long)mem_stats.NS_VM_INTR;
76 cpu->nCtxSwitches = (unsigned long long)mem_stats.NS_VM_SWTCH; 76 cpu->nCtxSwitches = (unsigned long long)mem_stats.NS_VM_SWTCH;
77 cpu->swapIn = (unsigned long long)mem_stats.NS_VM_SWAPIN; 77 cpu->swapIn = (unsigned long long)mem_stats.NS_VM_SWAPIN;
78@@ -205,7 +215,8 @@ 78@@ -201,11 +211,37 @@
 79 #ifdef NS_VM_PAGEOUT
 80 cpu->pageOut = (unsigned long long)mem_stats.NS_VM_PAGEOUT;
 81 #endif
 82+#if defined(__NetBSD__)
 83+ {
 84+ NETSNMP_CPU_STATS *ncpu_stats;
 85+ size_t ncpu_size = sizeof(*ncpu_stats) * cpu_num * CPUSTATES;
 86+ ncpu_stats = malloc(ncpu_size);
 87+ int i;
 88+ if (ncpu_stats == NULL) {
 89+ snmp_log(LOG_ERR, "no memory for kern.cp_time (errno %d)\n", errno);
 90+ return;
 91+ }
 92+ if (sysctlbyname("kern.cp_time", ncpu_stats, &ncpu_size, NULL, 0) == -1)
 93+ snmp_log(LOG_ERR, "sysctl kern.cp_time failed (errno %d)\n", errno);
 94+ for (i = 0; i < cpu_num; i++) {
 95+ netsnmp_cpu_info *ncpu = netsnmp_cpu_get_byIdx( i, 1 );
 96+ size_t j = i * CPUSTATES;
 97+ ncpu->user_ticks = (unsigned long long)ncpu_stats[j + CP_USER];
 98+ ncpu->nice_ticks = (unsigned long long)ncpu_stats[j + CP_NICE];
 99+ ncpu->sys2_ticks = (unsigned long long)ncpu_stats[j + CP_SYS]+cpu_stats[j + CP_INTR];
 100+ ncpu->kern_ticks = (unsigned long long)ncpu_stats[j + CP_SYS];
 101+ ncpu->idle_ticks = (unsigned long long)ncpu_stats[j + CP_IDLE];
 102+ ncpu->intrpt_ticks = (unsigned long long)ncpu_stats[j + CP_INTR];
 103+ }
 104+ free(ncpu_stats);
 105+ }
 106+#endif
 107
79 #ifdef NETSNMP_KERN_MCPU 108 #ifdef NETSNMP_KERN_MCPU
80 mcpu_size = cpu_num*sizeof(NETSNMP_KERN_MCPU_TYPE); 109 mcpu_size = cpu_num*sizeof(NETSNMP_KERN_MCPU_TYPE);
81 mcpu_stats = malloc(mcpu_size); 110 mcpu_stats = malloc(mcpu_size);
82- sysctl(mcpu_mib, 2, mcpu_stats, &mcpu_size, NULL, 0); 111- sysctl(mcpu_mib, 2, mcpu_stats, &mcpu_size, NULL, 0);
83+ if (sysctl(mcpu_mib, 2, mcpu_stats, &mcpu_size, NULL, 0) == -1) 112+ if (sysctl(mcpu_mib, 2, mcpu_stats, &mcpu_size, NULL, 0) == -1)
84+ snmp_log(LOG_ERR, "sysctl kern.mcpu failed (errno %d)\n", errno); 113+ snmp_log(LOG_ERR, "sysctl kern.mcpu failed (errno %d)\n", errno);
85 for ( i = 0; i < cpu_num; i++ ) { 114 for ( i = 0; i < cpu_num; i++ ) {
86 cpu = netsnmp_cpu_get_byIdx( i, 0 ); 115 cpu = netsnmp_cpu_get_byIdx( i, 0 );
87 /* XXX - per-CPU statistics - mcpu_mib[i].??? */ 116 /* XXX - per-CPU statistics - mcpu_mib[i].??? */