mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-22 22:34:23 -07:00
* usr/lib/byobu/network:
- make network calculations drastically cheaper, by using status_freq rather than a file stat
This commit is contained in:
parent
598a3aa3f0
commit
be7e9d7d12
2 changed files with 48 additions and 49 deletions
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -47,6 +47,9 @@ byobu (4.30) unreleased; urgency=low
|
||||||
- combine mem_* to memory
|
- combine mem_* to memory
|
||||||
- decrease raid status frequency
|
- decrease raid status frequency
|
||||||
- add trailing space to logo
|
- add trailing space to logo
|
||||||
|
* usr/lib/byobu/network:
|
||||||
|
- make network calculations drastically cheaper, by using status_freq
|
||||||
|
rather than a file stat
|
||||||
|
|
||||||
-- Dustin Kirkland <kirkland@ubuntu.com> Thu, 11 Aug 2011 10:31:31 -0500
|
-- Dustin Kirkland <kirkland@ubuntu.com> Thu, 11 Aug 2011 10:31:31 -0500
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,12 @@ __network_detail() {
|
||||||
|
|
||||||
__network() {
|
__network() {
|
||||||
get_network_interface; local interface="$_RET"
|
get_network_interface; local interface="$_RET"
|
||||||
local t1=0 t2=0 x1=0 x2=0
|
local x1=0 x2=0
|
||||||
|
status_freq network
|
||||||
|
t="$_RET"
|
||||||
# By default, we won't bug the user with the display of network traffic
|
# 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
|
# below NETWORK_THRESHOLD in kbps; override in $BYOBU_CONFIG_DIR/status
|
||||||
[ -n "$NETWORK_THRESHOLD" ] || NETWORK_THRESHOLD=20
|
[ -n "$NETWORK_THRESHOLD" ] || NETWORK_THRESHOLD=20
|
||||||
t2=`date +%s`
|
|
||||||
OIFS=$IFS
|
OIFS=$IFS
|
||||||
for i in up down; do
|
for i in up down; do
|
||||||
unit="kbps"
|
unit="kbps"
|
||||||
|
@ -39,54 +40,49 @@ __network() {
|
||||||
down) symbol="$ICON_DN" ;;
|
down) symbol="$ICON_DN" ;;
|
||||||
esac
|
esac
|
||||||
cache="$BYOBU_RUN_DIR/network.$i"
|
cache="$BYOBU_RUN_DIR/network.$i"
|
||||||
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
|
[ -r "$cache" ] && read x1 < "$cache" || tx1=0
|
||||||
if [ $t2 -le $t1 ]; then
|
IFS="$OIFS:"
|
||||||
rate=0
|
while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do
|
||||||
else
|
if [ "$iface" = "${interface}" ]; then
|
||||||
[ -r "$cache" ] && read x1 < "$cache" || tx1=0
|
[ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes}
|
||||||
IFS="$OIFS:"
|
break;
|
||||||
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
|
|
||||||
done < /proc/net/dev
|
|
||||||
IFS=$OIFS
|
|
||||||
echo "$x2" > "$cache"
|
|
||||||
rate=$((8*($x2 - $x1) / ($t2 - $t1) / 1024)) # in kbps
|
|
||||||
[ "$rate" -lt 0 ] && rate=0
|
|
||||||
if [ $rate -gt $NETWORK_THRESHOLD ]; then
|
|
||||||
case "$NETWORK_UNITS" in
|
|
||||||
bytes)
|
|
||||||
rate=$(($rate/8))
|
|
||||||
if [ "$rate" -gt 1048576 ]; then
|
|
||||||
fpdiv "$rate" 1048576 1
|
|
||||||
rate=${_RET}
|
|
||||||
unit="GB/s"
|
|
||||||
elif [ "$rate" -gt 1024 ]; then
|
|
||||||
fpdiv "$rate" 1024 1
|
|
||||||
rate=${_RET}
|
|
||||||
unit="MB/s"
|
|
||||||
else
|
|
||||||
unit="kB/s"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# Default to bps
|
|
||||||
# Why 1000 and not 1024? http://en.wikipedia.org/wiki/Data_rate_units
|
|
||||||
if [ "$rate" -gt 1000000 ]; then
|
|
||||||
fpdiv "$rate" 1000000 1
|
|
||||||
rate=${_RET}
|
|
||||||
unit="Gbps"
|
|
||||||
elif [ "$rate" -gt 1000 ]; then
|
|
||||||
fpdiv "$rate" 1000 1
|
|
||||||
rate=${_RET}
|
|
||||||
unit="Mbps"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
|
|
||||||
fi
|
fi
|
||||||
|
done < /proc/net/dev
|
||||||
|
IFS=$OIFS
|
||||||
|
echo "$x2" > "$cache"
|
||||||
|
rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps
|
||||||
|
[ "$rate" -lt 0 ] && rate=0
|
||||||
|
if [ $rate -gt $NETWORK_THRESHOLD ]; then
|
||||||
|
case "$NETWORK_UNITS" in
|
||||||
|
bytes)
|
||||||
|
rate=$(($rate/8))
|
||||||
|
if [ "$rate" -gt 1048576 ]; then
|
||||||
|
fpdiv "$rate" 1048576 1
|
||||||
|
rate=${_RET}
|
||||||
|
unit="GB/s"
|
||||||
|
elif [ "$rate" -gt 1024 ]; then
|
||||||
|
fpdiv "$rate" 1024 1
|
||||||
|
rate=${_RET}
|
||||||
|
unit="MB/s"
|
||||||
|
else
|
||||||
|
unit="kB/s"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Default to bps
|
||||||
|
# Why 1000 and not 1024? http://en.wikipedia.org/wiki/Data_rate_units
|
||||||
|
if [ "$rate" -gt 1000000 ]; then
|
||||||
|
fpdiv "$rate" 1000000 1
|
||||||
|
rate=${_RET}
|
||||||
|
unit="Gbps"
|
||||||
|
elif [ "$rate" -gt 1000 ]; then
|
||||||
|
fpdiv "$rate" 1000 1
|
||||||
|
rate=${_RET}
|
||||||
|
unit="Mbps"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue