fix network-* when 0 byte rate

This commit is contained in:
Dustin Kirkland 2009-04-07 00:31:45 -07:00
commit 988bf35d34
2 changed files with 20 additions and 24 deletions

View file

@ -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{-} "

View file

@ -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{-} "