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/ssh/

memory

Memory of a Linux by SSH: total, used and available as the kernel counts it (MemAvailable).

  • linux
  • ssh
  • memory
  • alpine
  • debian
  • fedora

by banshee1 installation2 versions

Keen 1.0.0 · 36 lines
// The memory of a Linux, by SSH: the memory the kernel says is available (MemAvailable), which counts what
// caches and buffers would give back on demand; used memory is the rest. Swap is the linux/ssh/swap collector.
// Reads /proc/meminfo with cat: the kernel writes it the same way on Alpine, Debian and Fedora.
// MemAvailable exists since kernel 3.14; on an older kernel the collector stops rather than guess.
need('protocol:ssh');

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('used-percent', 'number', array('label' => 'Used memory', 'unit' => '%'));

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

// One line per figure, "MemAvailable:    3876540 kB", sizes in KiB.
$meminfo = ssh.run('cat /proc/meminfo');
$kib = array();
foreach (text.lines($meminfo['output']) as $line) {
    $m = text.match($line, '^([A-Za-z0-9_()]+): +([0-9]+)');
    if (list.count($m) > 0) {
        $kib[$m[1]] = $m[2];
    }
}
if (!list.has($kib, 'MemTotal') || $kib['MemTotal'] <= 0) {
    fail('misconfigured', 'No MemTotal in /proc/meminfo', $meminfo['errors']);
}
if (!list.has($kib, 'MemAvailable')) {
    fail('misconfigured', 'No MemAvailable in /proc/meminfo: kernel older than 3.14');
}

$total = $kib['MemTotal'] / 1024;
$available = $kib['MemAvailable'] / 1024;
value('total', number.round($total));
value('available', number.round($available));
value('used', number.round($total - $available));
value('used-percent', number.round(100 * ($total - $available) / $total, 1));