1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#!/bin/bash
# An example script for the genmon plugin displaying the bandwidth
# The first parameter passed to the script is the name of the interface
if=${1:-eth0}
test -d /sys/class/net/$if || echo "<txt>no $if</txt><tool>No statistics for $i</tool>"
prx=$(cat /sys/class/net/$if/statistics/rx_bytes)
ptx=$(cat /sys/class/net/$if/statistics/tx_bytes)
sleep 1
crx=$(cat /sys/class/net/$if/statistics/rx_bytes)
ctx=$(cat /sys/class/net/$if/statistics/tx_bytes)
brx=$(($crx - $prx))
btx=$(($ctx - $ptx))
human_bandwidth () {
bandwidth=$1
p=0
while [ "$bandwidth" -gt "1024" -a "$p" -le "3" ] ; do
bandwidth=$(($bandwidth/1024))
p=$(($p+1))
done
case $p in
0)
bandwidth="$bandwidth B/s"
;;
1)
bandwidth="$bandwidth KB/s"
;;
2)
bandwidth="$bandwidth MB/s"
;;
esac
echo $bandwidth
}
rx=$(human_bandwidth $brx)
tx=$(human_bandwidth $btx)
echo "<txt>Rx: $rx - Tx: $tx</txt>"
echo "<tool>Bandwidth on interface $if</tool>"
|