8 PMbwmon - Poor man's bandwidth monitor
19 echo "Usage: $0 [kMG][bB]" >&2
36 case "${prefix:0:1}" in
39 G
) qt
=$
[1024*1024*1024];;
44 if [ "${#prefix}" -gt 1 ]; then
45 case "${prefix:1:1}" in
59 for master
in `cat /sys/class/net/bonding_masters 2>/dev/null`
64 eval "$var=($(cat /sys/class/net/$master/bonding/slaves))"
69 [ ! -d "$iface" ] && continue
70 [ "$iface" = lo
] && continue
72 rx0
[$iface]=${rx1[$iface]:-0}
73 tx0
[$iface]=${tx1[$iface]:-0}
74 rx1
[$iface]=`cat /sys/class/net/$iface/statistics/rx_bytes`
75 tx1
[$iface]=`cat /sys/class/net/$iface/statistics/tx_bytes`
77 rxd
[$iface]=$
[ ${rx1[$iface]} - ${rx0[$iface]} ]
78 txd
[$iface]=$
[ ${tx1[$iface]} - ${tx0[$iface]} ]
82 printf "%6s - RX: %8d TX: %8d %sps" "$iface" $
[ ${rxd[$iface]} / $qt ] $
[ ${txd[$iface]} / $qt ] "$prefix"
84 if [ -n "${masters[$iface]}" ]
90 eval "slaves=(\${slaves_$iface[@]})"
92 for slave
in "${slaves[@]}"
94 taps_rx_sum
=$
[ $taps_rx_sum + ${rxd[$slave]} ]
95 taps_tx_sum
=$
[ $taps_tx_sum + ${txd[$slave]} ]
97 taps_rx_sum
=$
[ $taps_rx_sum / $qt ]
98 taps_tx_sum
=$
[ $taps_tx_sum / $qt ]
99 bond_rx
=$
[ ${rxd[$iface]} / $qt ]
100 bond_tx
=$
[ ${txd[$iface]} / $qt ]
104 if [ $taps_rx_sum -ne 0 -a $taps_rx_sum -ne $bond_rx ]
106 rx_comp_rt
=$
[ ${bond_rx} / $taps_rx_sum ]
108 if [ $taps_tx_sum -ne 0 -a $taps_tx_sum -ne $bond_tx ]
110 tx_comp_rt
=$
[ ${bond_tx} / $taps_tx_sum ]
113 printf " - comp%% RX: %5.1f%% TX: %5.1f%%" "$rx_comp_rt" "$tx_comp_rt"