Windows
banshee/windows-collection/windows/snmp/
memory
The physical memory of a Windows, used and free, by SNMP
by banshee1 installation2 versions
// The physical memory of a Windows, by SNMP, from the "Physical Memory" row of hrStorageTable
// (HOST-RESOURCES-MIB). The paging file is the collector windows/snmp/swap.
need('protocol:snmp');
output('total', 'number', array('label' => 'Physical memory', 'unit' => 'MiB'));
output('used', 'number', array('label' => 'Memory used', 'unit' => 'MiB'));
output('free', 'number', array('label' => 'Free memory', 'unit' => 'MiB'));
output('used-percent', 'number', array('label' => 'Memory used', 'unit' => '%'));
watch.above('used-percent', 'Memory saturated', 'used-percent', array('warning' => 90, 'critical' => 95, 'for' => '3 runs'));
watch.below('free', 'Little free memory', 'free', array('critical' => 512, 'enabled' => false));
// hrStorageTable, indexed by hrStorageIndex: hrStorageType (an OID), hrStorageAllocationUnits (in bytes),
// hrStorageSize and hrStorageUsed (in allocation units).
$storage = snmp.table(array(
'type' => '1.3.6.1.2.1.25.2.3.1.2',
'unit' => '1.3.6.1.2.1.25.2.3.1.4',
'size' => '1.3.6.1.2.1.25.2.3.1.5',
'used' => '1.3.6.1.2.1.25.2.3.1.6',
));
// Physical memory is of the type hrStorageRam (1.3.6.1.2.1.25.2.1.2); the pattern accepts the OID written
// with or without a leading dot.
// An empty table, a type in a form the pattern does not recognise, or a zero size stop the
// collector, saying which types were read: never a green light without a measure.
$found = false;
$types = array();
foreach ($storage as $row) {
$types = list.add($types, list.get($row, 'type', ''));
if (text.like(list.get($row, 'type', ''), '*1.3.6.1.2.1.25.2.1.2')) {
$found = true;
$ram = $row;
break;
}
}
if (!$found) {
fail('misconfigured', 'Physical memory (hrStorageRam) missing from hrStorageTable',
list.count($types) . ' row(s) read; types: ' . text.join($types, ', '));
}
if (list.get($ram, 'size', 0) <= 0) {
fail('misconfigured', 'Physical memory of zero size in hrStorageTable');
}
$total = $ram['size'] * $ram['unit'] / 1048576;
$used = $ram['used'] * $ram['unit'] / 1048576;
value('total', number.round($total));
value('used', number.round($used));
value('free', number.round($total - $used));
value('used-percent', number.round(100 * $used / $total, 1));