Measuring CPU usage via SNMP

Dan Nelson dnelson at
Tue May 5 21:55:43 UTC 2009

In the last episode (May 05), Maxim Khitrov said:
> Simple question - does the sum of differences in ssCpuRawIdle,
> ssCpuRawUser, ssCpuRawNice, ssCpuRawKernel, and ssCpuRawInterrupt OIDs on
> a FreeBSD 7.2 system give me total CPU allocation (i.e.  is a constant)? 
> I've configured a few scripts to read these values from bsnmpd, store them
> via rrdtool, and then generate a single graph with idle on the negative y
> axis and everything else stacked on top.  I want to make sure that no
> other counter is missing from this ensemble and the ones listed do not
> overlap.  If either of those conditions is not met, my usage percent
> calculation will not be accurate.
> The OIDs that I left out are:
> ssCpuRawSoftIRQ - documentation states that this is for Linux only,
> but FreeBSD 7.2 does provide a value for it
> ssCpuRawWait - always 0?
> ssCpuRawSystem - seems to be a sum of ssCpuRawKernel and ssCpuRawInterrupt
> As far as I can tell, these three do not factor into the equation. The
> only one I'm not sure about is ssCpuRawSystem.  Is there ever a time when
> it will not equal to ssCpuRawKernel + ssCpuRawInterrupt?

The nice thing about open source software is you can read the source and see
what's going on :)  The FreeBSD kernel statclock() function:

updates the cp_time[] array, and it increments one of CP_NICE, CP_USER,
CP_INTR, CP_SYS, and CP_IDLE on each tick.  

The Net-SNMP var_extensible_vmstat() function:

fetches that array and maps those indexes to CPURAWNICE, CPURAWUSER,
CPURAWINTR, CPURAWKERNEL, and CPURAWIDLE.  So fetching the matching
ssCpuRaw* oids and totaling them up should always equal 100% cpu.

	Dan Nelson
	dnelson at

More information about the freebsd-questions mailing list