shell获取网卡流量

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kongshuai19900505/article/details/80495716
#!/bin/bash


eth=$1
if [ -z $eth ]
then
   eth=bond0 
fi


# 1000Mbps = 125000000
# 100Mbps = 12500000
rate=125000000


echo $eth
eth=eth1
rx_pre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')
tx_pre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')
sleep 1
rx_next=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')
tx_next=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')
#clear
#echo  -e  "\tRX\t\tTX\t\tR_Rate\tT_Rate\t`date +%k:%M:%S`"
rx_data=$((${rx_next}-${rx_pre}))
tx_data=$((${tx_next}-${tx_pre}))


rx_tmp=$rx_data
tx_tmp=$tx_data


rx_data=$(echo $rx_data | awk '{print $1 }')
tx_data=$(echo $tx_data | awk '{print $1 }')


R_Rate=$(( $rx_tmp / $rate))
T_Rate=$(( $tx_tmp / $rate))
echo "flow_in" : ${rx_data},
echo "flow_out" : ${tx_data},
展开阅读全文

没有更多推荐了,返回首页