banshee is under active development: collectors will keep changing, and a version you publish will likely need adjustments. For stable use, wait for version 1.0.0.

Linux

banshee/linux-collection/linux/snmp/

memory

Physical memory of a Linux host by SNMP, buffers and cache counted as available.

  • linux
  • snmp
  • memory
  • net-snmp

by banshee1 installation2 versions

Keen 1.0.0 · 50 lines
// The physical memory of a Linux host, by SNMP, from the memory group of UCD-SNMP-MIB (net-snmp).
// Available memory is the kernel's own estimate, MemAvailable, which net-snmp 5.9 and later serve as
// memSysAvail. An older agent does not serve it: available memory is then free memory, buffers and cache,
// which the kernel gives back as soon as it is asked, and slightly overestimated (shared memory and tmpfs
// count as available). The "source" output says which one was used. Swap is the linux/snmp/swap collector.
// memTotalReal, memAvailReal, memBuffer and memCached are 31 bits wide, in KiB: beyond 2 TiB, the agent
// itself miscounts them.
need('protocol:snmp');

output('total', 'number', array('label' => 'Physical memory', 'unit' => 'MiB'));
output('used', 'number', array('label' => 'Used memory', 'unit' => 'MiB'));
output('available', 'number', array('label' => 'Available memory', 'unit' => 'MiB'));
output('cache', 'number', array('label' => 'Buffers and cache', 'unit' => 'MiB'));
output('used-percent', 'number', array('label' => 'Used memory', 'unit' => '%'));
output('source', 'text', array('label' => 'Source of available memory'));

watch.above('used-percent', 'Memory saturated', 'used-percent', array('warning' => 90, 'critical' => 95, 'for' => '3 runs'));
watch.below('available', 'Low available memory', 'available', array('critical' => 512, 'enabled' => false));

// memTotalReal, memAvailReal (the free memory), memBuffer and memCached, in KiB.
$total = snmp.get('1.3.6.1.4.1.2021.4.5.0') / 1024;
$free = snmp.get('1.3.6.1.4.1.2021.4.6.0') / 1024;
$buffers = snmp.get('1.3.6.1.4.1.2021.4.14.0') / 1024;
$cached = snmp.get('1.3.6.1.4.1.2021.4.15.0') / 1024;
if ($total <= 0) {
    fail('misconfigured', 'Physical memory of size zero (memTotalReal)');
}

// memSysAvail, in KiB. An agent that does not have it answers "not found", and the sum takes its place;
// any other failure stops the collector, in the state the call itself would give.
$system_available = snmp.get('1.3.6.1.4.1.2021.4.27.0', errors=$err);
if ($err['code'] == 'access_denied') {
    fail('misconfigured', 'memSysAvail refused by the agent', $err['text']);
}
if ($err['code'] != '' && $err['code'] != 'snmp_not_found') {
    fail('unreachable', 'memSysAvail unreadable', $err['text']);
}
$available = $free + $buffers + $cached;
$source = 'free-buffers-cache';
if ($err['code'] == '') {
    $available = $system_available / 1024;
    $source = 'memavailable';
}

value('total', number.round($total));
value('used', number.round($total - $available));
value('available', number.round($available));
value('cache', number.round($buffers + $cached));
value('used-percent', number.round(100 * ($total - $available) / $total, 1));
value('source', $source);