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,10 +40,6 @@ __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
|
|
||||||
if [ $t2 -le $t1 ]; then
|
|
||||||
rate=0
|
|
||||||
else
|
|
||||||
[ -r "$cache" ] && read x1 < "$cache" || tx1=0
|
[ -r "$cache" ] && read x1 < "$cache" || tx1=0
|
||||||
IFS="$OIFS:"
|
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
|
||||||
|
@ -53,7 +50,7 @@ __network() {
|
||||||
done < /proc/net/dev
|
done < /proc/net/dev
|
||||||
IFS=$OIFS
|
IFS=$OIFS
|
||||||
echo "$x2" > "$cache"
|
echo "$x2" > "$cache"
|
||||||
rate=$((8*($x2 - $x1) / ($t2 - $t1) / 1024)) # in kbps
|
rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps
|
||||||
[ "$rate" -lt 0 ] && rate=0
|
[ "$rate" -lt 0 ] && rate=0
|
||||||
if [ $rate -gt $NETWORK_THRESHOLD ]; then
|
if [ $rate -gt $NETWORK_THRESHOLD ]; then
|
||||||
case "$NETWORK_UNITS" in
|
case "$NETWORK_UNITS" in
|
||||||
|
@ -87,7 +84,6 @@ __network() {
|
||||||
esac
|
esac
|
||||||
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
|
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue