Linux
banshee/linux-collection/linux/snmp/
cpu
Processor load of a Linux host by SNMP: each processor, the average, and user, system, I/O wait and steal time.
by banshee1 installation2 versions
// The processor load of a Linux host, by SNMP (net-snmp). Each logical processor, from hrProcessorLoad
// (HOST-RESOURCES-MIB), which the agent itself averages over the last minute. The whole machine, its load
// and how it splits (user, system, waiting for disks, time stolen by the hypervisor), from the ssCpuRaw*
// counters (UCD-SNMP-MIB), over the interval between two runs: nothing on the first run.
// The overall load counts time spent waiting for disks as idle, as the linux/ssh/cpu collector does; it
// covers the interval, not the last minute, so it is not the mean of the processors. The ssCpuRaw*
// counters are 32 bits wide: on a large machine they wrap within days, and that run returns nothing.
need('protocol:snmp');
per('core', 'Processors');
output('cpu-busy', 'number', array('label' => 'Average load', 'unit' => '%'));
output('user', 'number', array('label' => 'User time', 'unit' => '%'));
output('system', 'number', array('label' => 'System time', 'unit' => '%'));
output('iowait', 'number', array('label' => 'Waiting for disks', 'unit' => '%'));
output('steal', 'number', array('label' => 'Stolen by the hypervisor', 'unit' => '%'));
output('core-busy', 'number', array('label' => 'Processor load', 'unit' => '%', 'per' => 'core'));
output('cores', 'number', array('label' => 'Number of processors'));
watch.above('cpu-high', 'Saturation', 'cpu-busy', array('warning' => 85, 'critical' => 95, 'for' => '3 runs'));
watch.above('iowait-high', 'Waiting for disks', 'iowait', array('warning' => 20, 'for' => '3 runs', 'enabled' => false));
watch.above('steal-high', 'Processor taken by the hypervisor', 'steal', array('warning' => 10, 'for' => '3 runs'));
watch.above('core-hot', 'A saturated processor', 'core-busy', array('warning' => 95, 'for' => '3 runs', 'enabled' => false));
watch.deviate('core-neglected', 'A processor left idle', 'core-busy', array('side' => 'below', 'warning' => 30, 'enabled' => false));
watch.expect('core-count', 'Unexpected number of processors', 'cores');
// ssCpuRaw*, in hundredths of a second since boot, for all processors together: User, Nice, System,
// Idle, Wait, Interrupt, SoftIRQ and Steal, the fields of the "cpu" line of /proc/stat. On Linux,
// ssCpuRawSystem counts neither interrupts nor waiting, and ssCpuRawKernel is zero: it is not read.
// Every counter is read on every run, so that the next run has its rate.
$user = counter.rate('user', snmp.get('1.3.6.1.4.1.2021.11.50.0'));
$nice = counter.rate('nice', snmp.get('1.3.6.1.4.1.2021.11.51.0'));
$system = counter.rate('system', snmp.get('1.3.6.1.4.1.2021.11.52.0'));
$idle = counter.rate('idle', snmp.get('1.3.6.1.4.1.2021.11.53.0'));
$wait = counter.rate('wait', snmp.get('1.3.6.1.4.1.2021.11.54.0'));
$interrupt = counter.rate('interrupt', snmp.get('1.3.6.1.4.1.2021.11.56.0'));
$softirq = counter.rate('softirq', snmp.get('1.3.6.1.4.1.2021.11.61.0'));
$steal = counter.rate('steal', snmp.get('1.3.6.1.4.1.2021.11.64.0'));
if ($user == '' || $nice == '' || $system == '' || $idle == '' || $wait == '' || $interrupt == '' || $softirq == '' || $steal == '') {
skip('First reading, or counters gone backwards: the load comes on the next run');
}
$total = $user + $nice + $system + $idle + $wait + $interrupt + $softirq + $steal;
if ($total <= 0) {
skip('No processor time counted since the previous run');
}
// hrProcessorLoad, one row per logical processor, by hrDeviceIndex: the load in percent. The index means
// nothing to a reader; processors are named cpu0, cpu1… in the agent's order.
$loads = snmp.walk('1.3.6.1.2.1.25.3.3.1.2');
$cores = 0;
foreach ($loads as $load) {
value('core-busy', $load, 'cpu' . $cores);
$cores = $cores + 1;
}
if ($cores == 0) {
fail('misconfigured', 'The agent does not serve the processor table (hrProcessorTable)');
}
value('cores', $cores);
// User time includes low-priority tasks (Nice); system time includes interrupts.
value('cpu-busy', number.round(100 * (1 - ($idle + $wait) / $total), 1));
value('user', number.round(100 * ($user + $nice) / $total, 1));
value('system', number.round(100 * ($system + $interrupt + $softirq) / $total, 1));
value('iowait', number.round(100 * $wait / $total, 1));
value('steal', number.round(100 * $steal / $total, 1));