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

- fix input-field-separator problems with /proc/net/dev parsing
This commit is contained in:
Dustin Kirkland 2012-01-18 17:46:26 -06:00
commit ab37251175
3 changed files with 26 additions and 11 deletions

3
debian/changelog vendored
View file

@ -1,6 +1,7 @@
byobu (5.5) unreleased; urgency=low
* UNRELEASED
* usr/lib/byobu/ec2_cost, usr/lib/byobu/network:
- fix input-field-separator problems with /proc/net/dev parsing
-- Dustin Kirkland <kirkland@ubuntu.com> Tue, 17 Jan 2012 12:56:23 -0600

View file

@ -33,7 +33,6 @@ __ec2_cost_detail() {
__ec2_cost() {
local zone type file_to_stat cpu mem rate hours tx_gb rx_gb network_cost uptime_cost total_cost interface cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ec2_cost"
OIFS="$IFS"
# Try to use metadata service
if metadata_available; then
[ -s "$cache.zone" ] || wget -q -O "$cache.zone" http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null &
@ -76,15 +75,26 @@ __ec2_cost() {
# 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
IFS="$OIFS:"
while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do
case "$iface" in
${interface}:)
tx_gb=${tbytes}
rx_gb=${rbytes}
break;
;;
${interface}:*)
# Interface and rbytes got munged together
tx_gb=${rmulticast##*:}
rx_gb=${iface##*:}
break;
;;
esac
if [ "$iface" = "${interface}:" ]; then
tx_gb=${tbytes}
rx_gb=${rbytes}
break
fi
done < /proc/net/dev
IFS="$OIFS"
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}'`

View file

@ -32,7 +32,6 @@ __network() {
# 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
@ -42,14 +41,19 @@ __network() {
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
IFS="$OIFS:"
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
case "$iface" in
${interface}:)
[ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes}
break;
;;
${interface}:*)
# Interface and tbytes got munged together
[ "$i" = "up" ] && x2=${iface##*:} || x2=${rmulticast##*:}
break;
;;
esac
done < /proc/net/dev
IFS="$OIFS"
echo "$x2" > "$cache"
rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps
[ "$rate" -lt 0 ] && rate=0