diff -prud byobu/old/ec2_cost byobu/new/ec2_cost --- byobu/old/ec2_cost 2012-01-09 02:35:58.000000000 +0000 +++ byobu/new/ec2_cost 2012-01-10 04:41:19.000000000 +0000 @@ -74,16 +74,9 @@ __ec2_cost() { hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1)) # Auto detect network interface interface=`tail -n1 /proc/net/route | awk '{print $1}'` - local iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed - while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do - if [ "$iface" = "${interface}:" ]; then - tx_gb=${tbytes} - rx_gb=${rbytes} - break; - fi - done < /proc/net/dev - tx_gb=$(echo ${tx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') - rx_gb=$(echo ${rx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') + interface=$( cat /proc/net/dev | grep "${interface}" | cut -d ':' -f 2 ) + tx_gb=$(echo ${interface} | awk '{print $9' | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') + rx_gb=$(echo ${interface} | awk '{print $1' | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'` # Calculate uptime cost uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$rate" * $hours}"` diff -prud byobu/old/network byobu/new/network --- byobu/old/network 2012-01-09 02:35:58.000000000 +0000 +++ byobu/new/network 2012-01-10 04:38:02.000000000 +0000 @@ -26,13 +26,12 @@ __network_detail() { __network() { get_network_interface; local interface="$_RET" - local x1=0 x2=0 tx1=0 i= t= unit= symbol= cache= rate= + local x1=0 x2=0 i= t= unit= symbol= cache= rate= status_freq network t="$_RET" # By default, we won't bug the user with the display of network traffic # below NETWORK_THRESHOLD in kbps; override in $BYOBU_CONFIG_DIR/status [ -n "$NETWORK_THRESHOLD" ] || NETWORK_THRESHOLD=20 - OIFS=$IFS for i in up down; do unit="kb" case $i in @@ -40,14 +39,9 @@ __network() { down) symbol="$ICON_DN" ;; esac cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/network.$i" - [ -r "$cache" ] && read x1 < "$cache" || tx1=0 - local iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed - while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do - if [ "$iface" = "${interface}:" ]; then - [ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes} - break; - fi - done < /proc/net/dev + [ -r "$cache" ] && read x1 < "$cache" || x1=0 + [ "$i" = "up" ] && x2=9 || x2=1 + x2=$( cat /proc/net/dev | grep "${interface}" | cut -d ':' -f 2 | awk "{print \$$x2}" ) echo "$x2" > "$cache" rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps [ "$rate" -lt 0 ] && rate=0