Linux
banshee/linux-collection/linux/ssh/
load
Load average of a Linux by SSH over 1, 5 and 15 minutes, raw and per core.
by banshee1 installation2 versions
// The load average of a Linux, by SSH, over 1, 5 and 15 minutes, and the same divided by the number of
// cores: a load of 1 per core keeps the whole machine busy.
// Reads /proc/loadavg with cat, and counts the cores with grep -c in /proc/stat (one "cpuN" line per online
// core): the kernel writes both the same way on Alpine, Debian and Fedora, and -c is an option of BusyBox
// as of GNU grep. /proc/cpuinfo is not read: its layout changes from one architecture to another.
need('protocol:ssh');
output('load-1', 'number', array('label' => 'Load, 1 minute'));
output('load-5', 'number', array('label' => 'Load, 5 minutes'));
output('load-15', 'number', array('label' => 'Load, 15 minutes'));
output('load-1-per-core', 'number', array('label' => 'Load per core, 1 minute'));
output('load-5-per-core', 'number', array('label' => 'Load per core, 5 minutes'));
output('load-15-per-core', 'number', array('label' => 'Load per core, 15 minutes'));
output('cores', 'number', array('label' => 'Number of cores'));
watch.above('load-high', 'Machine overloaded', 'load-5-per-core', array('warning' => 1.5, 'critical' => 3));
watch.habit('load-unusual', 'Unusual load', 'load-5-per-core', array('enabled' => false));
// Two lines: "0.52 0.58 0.59 1/467 12345", then the number of cores.
$read = ssh.run("cat /proc/loadavg; grep -c '^cpu[0-9]' /proc/stat");
$lines = text.lines($read['output']);
if (list.count($lines) != 2) {
fail('misconfigured', 'Unrecognised answer from /proc/loadavg and /proc/stat', $read['output'] . $read['errors']);
}
$load = text.words($lines[0]);
$cores = $lines[1];
if (list.count($load) < 3 || !text.is_number($load[0]) || !text.is_number($load[1]) || !text.is_number($load[2])) {
fail('misconfigured', 'No load found in /proc/loadavg', $lines[0]);
}
if (!text.is_number($cores) || $cores < 1) {
fail('misconfigured', 'No core found in /proc/stat', $cores);
}
value('load-1', $load[0]);
value('load-5', $load[1]);
value('load-15', $load[2]);
value('load-1-per-core', number.round($load[0] / $cores, 2));
value('load-5-per-core', number.round($load[1] / $cores, 2));
value('load-15-per-core', number.round($load[2] / $cores, 2));
value('cores', $cores);