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.

Examples

banshee/examples-collection/examples/mechanics/

cache

Example: the cache, set, has, get and delete; a restart told by the boot id of the kernel.

  • example
  • cache
  • restart
  • ssh

by banshee1 installation1 version

v1Latest

Published on October 27, 2026. First version in this collection.

Keen 1.0.0 · 24 lines
// The cache: a few values the collector keeps from one pass to the next, each for a lifetime. Here, the
// boot id of the kernel, which changes at every start: a different one means the host restarted.
need('protocol:ssh');

output('restarted', 'text', array('label' => 'Restarted since the previous pass'));

watch.state('restart', 'Host restarted', 'restarted', array('warning' => array('yes')));

$read = ssh.run('cat /proc/sys/kernel/random/boot_id');
$boot_id = text.trim($read['output']);
if ($boot_id == '') {
    // cache.delete: forget the key; the next pass starts afresh, as a first one.
    cache.delete('boot-id');
    fail('misconfigured', 'No boot id in /proc/sys/kernel/random/boot_id', $read['errors']);
}

// cache.has before cache.get: get stops the collector on a key missing or expired.
$restarted = 'no';
if (cache.has('boot-id') && cache.get('boot-id') != $boot_id) {
    $restarted = 'yes';
}
// cache.set: kept one day (86 400 seconds); a probe stopped longer than that starts afresh.
cache.set('boot-id', $boot_id, 86400);
value('restarted', $restarted);