From d02cf9ca1e078faa5979f6103c4974022f67727b Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Sun, 8 Jan 2012 18:37:23 -0600 Subject: [PATCH] * usr/lib/byobu/ec2_cost, usr/lib/byobu/network: - use /proc/net/dev for network transfer calculations - fixes issue with ifconfig format changes --- debian/changelog | 3 +++ usr/lib/byobu/ec2_cost | 16 ++++++++++------ usr/lib/byobu/network | 4 +--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 605e867f..b6850c4b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,6 +14,9 @@ byobu (5.2) unreleased; urgency=low * usr/bin/Makefile.am, usr/lib/byobu/include/Makefile.am, usr/share/man/man1/Makefile.am: - install the byobu-layout tool and manpage + * usr/lib/byobu/ec2_cost, usr/lib/byobu/network: + - use /proc/net/dev for network transfer calculations + - fixes issue with ifconfig format changes -- Dustin Kirkland Thu, 29 Dec 2011 12:28:51 -0600 diff --git a/usr/lib/byobu/ec2_cost b/usr/lib/byobu/ec2_cost index ed24a550..b14a53c2 100755 --- a/usr/lib/byobu/ec2_cost +++ b/usr/lib/byobu/ec2_cost @@ -74,12 +74,16 @@ __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}'` - ifconfig_out=`LC_ALL=C /sbin/ifconfig "$interface"` - # Calculate bandwidth cost - tx_gb=${ifconfig_out#*RX bytes:} - tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') - rx_gb=${ifconfig_out#*TX bytes:} - rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') + 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 }') 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 --git a/usr/lib/byobu/network b/usr/lib/byobu/network index 2d7c63fb..5655a7d6 100755 --- a/usr/lib/byobu/network +++ b/usr/lib/byobu/network @@ -41,15 +41,13 @@ __network() { esac cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/network.$i" [ -r "$cache" ] && read x1 < "$cache" || tx1=0 - IFS="$OIFS:" 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 + if [ "$iface" = "${interface}:" ]; then [ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes} break; fi done < /proc/net/dev - IFS=$OIFS echo "$x2" > "$cache" rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps [ "$rate" -lt 0 ] && rate=0