Examples
banshee/examples-collection/examples/basics/
calculation
Example: + - * / %, number.round and the point that joins texts, on the uptime of a Linux.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
// Calculation: + - * / and %, their priorities, number.round, and the point that joins texts.
// The collector reads how long a Linux has been running, from /proc/uptime.
need('protocol:ssh');
output('uptime', 'number', array('label' => 'Time since start', 'unit' => 'd'));
output('uptime-text', 'text', array('label' => 'Time since start, in words'));
watch.below('rebooted', 'Restarted recently', 'uptime', array('warning' => 0.1));
// "350735.47 1374286.73": the seconds since the start, then the idle seconds of all the cores.
$read = ssh.run('cat /proc/uptime');
$words = text.words($read['output']);
$seconds = number.round($words[0]);
// / divides; number.round with a second argument keeps that many decimals.
value('uptime', number.round($seconds / 86400, 2));
// % is the rest of a division: the seconds left once the whole days are counted. * / and % come
// before + and -, and what is between parentheses comes first of all.
$days = ($seconds - $seconds % 86400) / 86400;
$hours = ($seconds % 86400 - $seconds % 3600) / 3600;
// The point joins texts, a number counting as its digits; it takes a blank on each side.
value('uptime-text', $days . ' d ' . $hours . ' h');