iptraf使用-linux 统计上下行流量

1.查看是否安装成功:yum list installed iptraf

2.查看帮助信息:iptraf -h

3. 查看有几块网卡:ip a

4.查看某个网卡的traffic监控:iptraf -i eth0

5.查看详细的网络信息,可以查看Incoming和Outgoing的带宽信息:iptraf -d eth0

6.查看tcp和udp的监控:iptraf -s eth0

7.查看数据包信息:iptraf -z  eth0

tmpf="./_eth_speed_tmp.file"

while [ 1 ]
do
	 busybox ifconfig eth0 > $tmpf

	#cat $tmpf
	
	txp=`cat $tmpf | grep "TX p" |  busybox sed -e "s/TX packets://" |  busybox awk '{print $1}'`
	txb=`cat $tmpf | grep "TX b" |  busybox awk '{print $6}' |  busybox sed -e 's/bytes://'`

	rxp=`cat $tmpf | grep "RX p" |  busybox sed -e "s/RX packets://" |  busybox awk '{print $1}'`
	rxb=`cat $tmpf | grep "RX b" |  busybox sed -e "s/RX bytes://" |  busybox awk '{print $1}'`

	#echo $txp
	#echo $txb

	#echo $rxp
	#echo $rxb
	
    if [ "$rp" != "" ] 
	then
                 busybox printf  "%s" `date`
		 busybox printf "RX:"
		 r=` busybox awk -v var="$(( $rxb - $rb ))" 'BEGIN{print var / 1024.0 /1024.0}'`	
		 busybox printf " %03.02f MB/S" $r 
		 busybox printf " %6d packets/s" $(( $rxp - $rp ))
		if [ "$rxb" != "$rb" ]
		then
			r=` busybox awk -v var="$(( $rxb - $rb ))" -v var2="$(( $rxp - $rp ))" 'BEGIN{print var / var2}'`	
			 busybox printf " %04.02f bytes/packet" $r
		else
			 busybox printf " ----.-- bytes/packet"
		fi
		
		echo ""
	fi

		
	tp=$txp
	tb=$txb
	rp=$rxp
	rb=$rxb
	
	sleep 1
done
tmpf="./_eth_speed_tmp.file"

while [ 1 ]
do
	 busybox ifconfig eth0 > $tmpf

	#cat $tmpf
	
	txp=`cat $tmpf | grep "TX p" |  busybox sed -e "s/TX packets://" |  busybox awk '{print $1}'`
	txb=`cat $tmpf | grep "TX b" |  busybox awk '{print $6}' |  busybox sed -e 's/bytes://'`

	rxp=`cat $tmpf | grep "RX p" |  busybox sed -e "s/RX packets://" |  busybox awk '{print $1}'`
	rxb=`cat $tmpf | grep "RX b" |  busybox sed -e "s/RX bytes://" |  busybox awk '{print $1}'`

	#echo $txp
	#echo $txb

	#echo $rxp
	#echo $rxb
	
	if [ "$tp" != "" ] 
	then
		 busybox printf "TX:"
	#	 printf "$txb bytes"
	#	t=` awk -v var="$txb" 'BEGIN{print var / 1024.0 /1024.0}'`	
	#	 printf " ($t MBytes)"
	#	 printf " $txp packets"
		t=` busybox awk -v var="$(( $txb - $tb ))" 'BEGIN{print var / 1024.0 /1024.0}'`	
		 busybox printf " %03.02f MB/S" $t 
		 busybox printf " %6d packets/s" $(( $txp - $tp ))
		if [ "$txb" != "$tb" ]
		then
			t=` busybox awk -v var="$(( $txb - $tb ))" -v var2="$(( $txp - $tp ))" 'BEGIN{print var / var2}'`	
			 busybox printf " %04.02f bytes/packet" $t
		else
			 busybox printf " ----.-- bytes/packet"
		fi
		
		echo ""
	fi
		
	tp=$txp
	tb=$txb
	rp=$rxp
	rb=$rxb
	
	sleep 1
done

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TestBandwitdth脚本用于测试带宽; //***************************************************************************************** 用法: 1.将“TestBandwidth.tar.gz”脚本copy到服务器上解压后,进入目录; 2.编辑“TestURL.sh”:灌流量; 上行:wget http://*** 下行:post http://*** 3.如果修改了步骤2,执行此步,否则跳过: 修改 TestBandwidth.tar.gz 脚本中的倒数5-6行; kill -9 `ps -ef|grep wget|grep http|awk '{print $2}'` //修改kill关键字:grep wget rm zhuxian* //修改rm关键字:zhuxian* 4.修改“bandwidth.sh”:修改检测网卡: netcard=em1 5.使用后台运行命令执行:nohup ./bandwidth.sh (注:停止脚本 pkill -9 bandwidth.sh && pkill -9 wget) 6.查看结果:BandwitdthResult.txt //********************************************************* 测试流量:清空“TestURL.sh”文件时执行就是测试流量 //***************************************************************************************** 脚本说明: 1.调用TestURL.sh脚本启动灌流量操作; 2.等待10s(防止刚开始下载时的流量冲高); 3.取当前网卡已接收的上行、下行数据流量; 4.等待5s; 5.取当前网卡已接收的上行、下行数据流量; 6.计算两次取值中间的差值,算平均值; 7.等待10s,开始下一次小循环(循环4次)(一次小循环70s); 8.清除下载进程,清除下载文件,清除下载日志; 9.等待3495s,开始下一次大循环(一次大循环1h);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值