* usr/lib/byobu/ec2_cost, usr/lib/byobu/network:

- use /proc/net/dev for network transfer calculations
  - fixes issue with ifconfig format changes
This commit is contained in:
Dustin Kirkland 2012-01-08 18:37:23 -06:00
commit d02cf9ca1e
3 changed files with 14 additions and 9 deletions

3
debian/changelog vendored
View file

@ -14,6 +14,9 @@ byobu (5.2) unreleased; urgency=low
* usr/bin/Makefile.am, usr/lib/byobu/include/Makefile.am, * usr/bin/Makefile.am, usr/lib/byobu/include/Makefile.am,
usr/share/man/man1/Makefile.am: usr/share/man/man1/Makefile.am:
- install the byobu-layout tool and manpage - 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 <kirkland@ubuntu.com> Thu, 29 Dec 2011 12:28:51 -0600 -- Dustin Kirkland <kirkland@ubuntu.com> Thu, 29 Dec 2011 12:28:51 -0600

View file

@ -74,12 +74,16 @@ __ec2_cost() {
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1)) hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
# Auto detect network interface # Auto detect network interface
interface=`tail -n1 /proc/net/route | awk '{print $1}'` interface=`tail -n1 /proc/net/route | awk '{print $1}'`
ifconfig_out=`LC_ALL=C /sbin/ifconfig "$interface"` local iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed
# Calculate bandwidth cost while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do
tx_gb=${ifconfig_out#*RX bytes:} if [ "$iface" = "${interface}:" ]; then
tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') tx_gb=${tbytes}
rx_gb=${ifconfig_out#*TX bytes:} rx_gb=${rbytes}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') 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}'` 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 # Calculate uptime cost
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$rate" * $hours}"` uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$rate" * $hours}"`

View file

@ -41,15 +41,13 @@ __network() {
esac esac
cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/network.$i" cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/network.$i"
[ -r "$cache" ] && read x1 < "$cache" || tx1=0 [ -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 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 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} [ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes}
break; break;
fi fi
done < /proc/net/dev done < /proc/net/dev
IFS=$OIFS
echo "$x2" > "$cache" echo "$x2" > "$cache"
rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps
[ "$rate" -lt 0 ] && rate=0 [ "$rate" -lt 0 ] && rate=0