Examples
banshee/examples-collection/examples/mechanics/
counter-rate
Example: counter.rate and skip; the incoming traffic of an interface in bit/s.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
// counter.rate: the rate per second of a counter, from its reading at the previous pass. It returns ''
// when there is no rate yet: at the first pass, after a long gap, or when the counter went back (a restart).
// skip then passes the turn: nothing is returned, and the probe keeps its state.
// The collector reads the incoming traffic of one interface of a Linux, by SSH.
need('protocol:ssh');
$interface = variable('example:network:interface', 'text', array(
'label' => 'Interface',
'help' => 'Its name on the host, for example eth0.',
));
output('traffic-in', 'number', array('label' => 'Incoming traffic', 'unit' => 'bit/s'));
watch.above('busy', 'Link busy', 'traffic-in', array('warning' => 800000000));
$read = ssh.run('cat', arguments=array('/sys/class/net/' . $interface . '/statistics/rx_bytes'));
if ($read['exit'] != 0) {
fail('misconfigured', 'No interface ' . $interface, $read['errors']);
}
// The counter is in bytes; times 8, the rate is in bits per second.
$rate = counter.rate('in', text.trim($read['output']) * 8);
if ($rate == '') {
skip('First reading: the traffic comes at the next pass');
}
value('traffic-in', number.round($rate));