8 PMbwmon - Poor man's bandwidth monitor
12 PMbwmon [kMG][B<bit> | B<Byte>] [I<INTERFACES>...]
21 .
/usr
/lib
/tool
/bash-utils
44 case "${prefix:0:1}" in
47 G
) qt
=$
[1024*1024*1024];;
52 if [ "${#prefix}" -gt 1 ]; then
67 for master
in `cat /sys/class/net/bonding_masters 2>/dev/null`
72 eval "$var=($(cat /sys/class/net/$master/bonding/slaves))"
77 [ ! -d "$iface" ] && continue
78 [ "$iface" = lo
] && continue
79 if [ -n "${ifaces[0]}" ]
82 for iface_pattern
in "${ifaces[@]}"
84 if [[ $iface_pattern =~ ^
(.
+)\
+$
]]
86 re
=${BASH_REMATCH[1]}.
+
87 if [[ $iface =~ ^
$re$
]]
91 elif [ "$iface" = "$iface_pattern" ]
106 rx0
[$iface]=${rx1[$iface]:-0}
107 tx0
[$iface]=${tx1[$iface]:-0}
108 rx1
[$iface]=`cat /sys/class/net/$iface/statistics/rx_bytes`
109 tx1
[$iface]=`cat /sys/class/net/$iface/statistics/tx_bytes`
111 rxd
[$iface]=$
[ ${rx1[$iface]} - ${rx0[$iface]} ]
112 txd
[$iface]=$
[ ${tx1[$iface]} - ${tx0[$iface]} ]
116 printf "%6s - RX: %8d TX: %8d %sps" "$iface" $
[ ${rxd[$iface]} / $qt ] $
[ ${txd[$iface]} / $qt ] "$prefix"
118 if [ -n "${masters[$iface]}" ]
124 eval "slaves=(\${slaves_$iface[@]})"
126 for slave
in "${slaves[@]}"
128 taps_rx_sum
=$
[ $taps_rx_sum + ${rxd[$slave]} ]
129 taps_tx_sum
=$
[ $taps_tx_sum + ${txd[$slave]} ]
131 taps_rx_sum
=$
[ $taps_rx_sum / $qt ]
132 taps_tx_sum
=$
[ $taps_tx_sum / $qt ]
133 bond_rx
=$
[ ${rxd[$iface]} / $qt ]
134 bond_tx
=$
[ ${txd[$iface]} / $qt ]
138 if [ $taps_rx_sum -ne 0 -a $taps_rx_sum -ne $bond_rx ]
140 rx_comp_rt
=$
[ ${bond_rx} / $taps_rx_sum ]
142 if [ $taps_tx_sum -ne 0 -a $taps_tx_sum -ne $bond_tx ]
144 tx_comp_rt
=$
[ ${bond_tx} / $taps_tx_sum ]
147 printf " - comp%% RX: %5.1f%% TX: %5.1f%%" "$rx_comp_rt" "$tx_comp_rt"