encapulate same codes into functions
use functions to avoid repeatly calling "cat" commad and make code cleaner Change-Id: If8a2643eb99f9acfcd94d9f042216bbaec7718cc
This commit is contained in:
parent
33c76dded5
commit
3535c14668
@ -3,16 +3,26 @@
|
|||||||
|
|
||||||
dev=${1:-eth0}
|
dev=${1:-eth0}
|
||||||
|
|
||||||
packages=`cat /sys/class/net/$dev/statistics/rx_packets `
|
function get_rx_packets()
|
||||||
bytes=`cat /sys/class/net/$dev/statistics/rx_bytes `
|
{
|
||||||
|
echo `cat /sys/class/net/$dev/statistics/rx_packets `
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_rx_bytes()
|
||||||
|
{
|
||||||
|
echo `cat /sys/class/net/$dev/statistics/rx_bytes `
|
||||||
|
}
|
||||||
|
|
||||||
|
packages=$(get_rx_packets)
|
||||||
|
bytes=$(get_rx_bytes)
|
||||||
|
|
||||||
interval=3
|
interval=3
|
||||||
|
|
||||||
trap 'break' INT
|
trap 'break' INT
|
||||||
while [ 1 -eq 1 ] ; do
|
while [ 1 -eq 1 ] ; do
|
||||||
sleep $interval
|
sleep $interval
|
||||||
n_packages=`cat /sys/class/net/$dev/statistics/rx_packets `
|
n_packages=$(get_rx_packets)
|
||||||
n_bytes=`cat /sys/class/net/$dev/statistics/rx_bytes `
|
n_bytes=$(get_rx_bytes)
|
||||||
python -c "print '%0.2f pkt/s %0.2f byte/s' % ((float($n_packages-$packages)/int($interval), (float($n_bytes-$bytes)/int($interval))))"
|
python -c "print '%0.2f pkt/s %0.2f byte/s' % ((float($n_packages-$packages)/int($interval), (float($n_bytes-$bytes)/int($interval))))"
|
||||||
packages=$n_packages
|
packages=$n_packages
|
||||||
bytes=$n_bytes
|
bytes=$n_bytes
|
||||||
|
Loading…
Reference in New Issue
Block a user