mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-22 06:23:19 -07:00
* usr/lib/byobu/ec2_cost, usr/lib/byobu/network: LP: #914098
- fix regression from r1839, add colon to IFS
This commit is contained in:
parent
7856650dda
commit
19dae74ed4
3 changed files with 10 additions and 3 deletions
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -14,6 +14,8 @@ byobu (5.3) unreleased; urgency=low
|
||||||
- use READLINK
|
- use READLINK
|
||||||
* usr/share/byobu/profiles/tmux:
|
* usr/share/byobu/profiles/tmux:
|
||||||
- add some comments
|
- add some comments
|
||||||
|
* usr/lib/byobu/ec2_cost, usr/lib/byobu/network: LP: #914098
|
||||||
|
- fix regression from r1839, add colon to IFS
|
||||||
|
|
||||||
-- Dustin Kirkland <kirkland@ubuntu.com> Sun, 08 Jan 2012 20:28:08 -0600
|
-- Dustin Kirkland <kirkland@ubuntu.com> Sun, 08 Jan 2012 20:28:08 -0600
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ __ec2_cost_detail() {
|
||||||
|
|
||||||
__ec2_cost() {
|
__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"
|
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
|
# Try to use metadata service
|
||||||
if metadata_available; then
|
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 &
|
[ -s "$cache.zone" ] || wget -q -O "$cache.zone" http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null &
|
||||||
|
@ -75,13 +76,15 @@ __ec2_cost() {
|
||||||
# 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}'`
|
||||||
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
|
||||||
|
IFS="$OIFS:"
|
||||||
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
|
||||||
tx_gb=${tbytes}
|
tx_gb=${tbytes}
|
||||||
rx_gb=${rbytes}
|
rx_gb=${rbytes}
|
||||||
break;
|
break
|
||||||
fi
|
fi
|
||||||
done < /proc/net/dev
|
done < /proc/net/dev
|
||||||
|
IFS="$OIFS"
|
||||||
tx_gb=$(echo ${tx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
|
tx_gb=$(echo ${tx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
|
||||||
rx_gb=$(echo ${rx_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}'`
|
||||||
|
|
|
@ -42,12 +42,14 @@ __network() {
|
||||||
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
|
||||||
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
|
||||||
|
IFS="$OIFS:"
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue