mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 22:13:19 -07:00
fix network-* when 0 byte rate
This commit is contained in:
parent
290ce20afc
commit
988bf35d34
2 changed files with 20 additions and 24 deletions
|
@ -29,17 +29,15 @@ t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
|
|||
t2=`date +%s`
|
||||
|
||||
if [ $t2 -le $t1 ]; then
|
||||
printf "v0 $unit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
x1=`cat "$cache"` 2>/dev/null || tx1=0
|
||||
x2=`ifconfig "$interface" | grep "RX bytes" | sed "s/^.*RX bytes://" | sed "s/ .*$//"`
|
||||
|
||||
echo "$x2" > "$cache"
|
||||
rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
|
||||
if [ "$rate" -gt 1024 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
|
||||
unit="MB/s"
|
||||
rate=0
|
||||
else
|
||||
x1=`cat "$cache"` 2>/dev/null || tx1=0
|
||||
x2=`ifconfig "$interface" | grep "RX bytes" | sed "s/^.*RX bytes://" | sed "s/ .*$//"`
|
||||
echo "$x2" > "$cache"
|
||||
rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
|
||||
if [ "$rate" -gt 1024 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
|
||||
unit="MB/s"
|
||||
fi
|
||||
fi
|
||||
printf "v\005{=b mw}$rate\005{-}\005{= mw}$unit\005{-} "
|
||||
|
|
|
@ -30,17 +30,15 @@ t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
|
|||
t2=`date +%s`
|
||||
|
||||
if [ $t2 -le $t1 ]; then
|
||||
printf "v0 $unit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
x1=`cat "$cache"` 2>/dev/null || tx1=0
|
||||
x2=`ifconfig "$interface" | grep "TX bytes" | sed "s/^.*TX bytes://" | sed "s/ .*$//"`
|
||||
|
||||
echo "$x2" > "$cache"
|
||||
rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
|
||||
if [ "$rate" -gt 1024 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
|
||||
unit="MB/s"
|
||||
rate=0
|
||||
else
|
||||
x1=`cat "$cache"` 2>/dev/null || tx1=0
|
||||
x2=`ifconfig "$interface" | grep "TX bytes" | sed "s/^.*TX bytes://" | sed "s/ .*$//"`
|
||||
echo "$x2" > "$cache"
|
||||
rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
|
||||
if [ "$rate" -gt 1024 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
|
||||
unit="MB/s"
|
||||
fi
|
||||
fi
|
||||
printf "^\005{=b mw}$rate\005{-}\005{= mw}$unit\005{-} "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue