mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-22 14:24:39 -07:00
* 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:
parent
ada44f8cff
commit
d02cf9ca1e
3 changed files with 14 additions and 9 deletions
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -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 <kirkland@ubuntu.com> Thu, 29 Dec 2011 12:28:51 -0600
|
||||
|
||||
|
|
|
@ -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}"`
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue