During performance tests related to measuring network throughput, it might be necessary to review the per second Bytes In/Out of a given interface.
While there are tools like iotop which provide a lot more features, here is a quick shell script based on 'ifconfig' which gives an instantaneous stat. Comes across very handy for me!
[root@nitro ~]# cat intstat.sh
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Usage: sh $0 <interface-name>"
exit 1
else
int_name=$1
fi
intval1=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
outval1=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
sleep 1
intval2=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
outval2=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
intdiff=`expr $intval2 - $intval1`
outdiff=`expr $outval2 - $outval1`
diffint_tmp=`expr $intval2 - $intval1`
diffout_tmp=`expr $outval2 - $outval1`
intdiff=`echo "$diffint_tmp / (1024 * 2)" | bc -l`
outdiff=`echo "$diffout_tmp / (1024 * 2)" | bc -l`
echo "Incoming rate = $intdiff Kilobytes per sec"
echo "Outgoing rate = $outdiff Kilobytes per sec"
While there are tools like iotop which provide a lot more features, here is a quick shell script based on 'ifconfig' which gives an instantaneous stat. Comes across very handy for me!
[root@nitro ~]# cat intstat.sh
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Usage: sh $0 <interface-name>"
exit 1
else
int_name=$1
fi
intval1=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
outval1=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
sleep 1
intval2=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
outval2=`ifconfig $int_name | grep "RX bytes" | awk '{print $2}' | cut -d: -f2`
intdiff=`expr $intval2 - $intval1`
outdiff=`expr $outval2 - $outval1`
diffint_tmp=`expr $intval2 - $intval1`
diffout_tmp=`expr $outval2 - $outval1`
intdiff=`echo "$diffint_tmp / (1024 * 2)" | bc -l`
outdiff=`echo "$diffout_tmp / (1024 * 2)" | bc -l`
echo "Incoming rate = $intdiff Kilobytes per sec"
echo "Outgoing rate = $outdiff Kilobytes per sec"
[root@nitro ~]# sh intstat.sh eth0
Incoming rate = .97265625000000000000 Kilobytes per sec
Outgoing rate = .97265625000000000000 Kilobytes per sec
No comments:
Post a Comment