This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please upgrade to a browser that supports web standards. It's free and painless.

林中求马 爰居爰处?爰丧其马? 予以求之?于林之下。
2010 八月 16, 星期一 林中求马 | 观点透视 [32] | 聚焦互联网 [28] | 生活轨迹 [24] | 國學精粹 [18] | 散文游记 [14] | 休闲娱乐 [13] | 听我讲故事 [6] | 图片库

«访民之口,甚于防川 | 工行纸黄金系统出bug»

查看网卡流量的脚本

calfen | 03 三月, 2009 11:59 (1298 Reads)

几点说明 :

  1. 该脚本用来放在服务器上查看网卡的目前流量.
  2. 该脚本只是大概统计流量,由于执行命令行需要消耗时间,故结果并不准确.但误差不大,可以看出流量趋势.
  3. 脚本的使用方法sh stream.sh $seconds,比如sh stream.sh 10表示10秒统计一次,sh stream.sh 1表示1秒一次.

#!/bin/bash
#monitor streams of LTS channels
#Write by calfen 20090227

timeOld=`date +%s`
eth0=`cat /proc/net/dev | grep eth0 | sed 's=^.*:==' `
eth1=`cat /proc/net/dev | grep eth1 | sed 's=^.*:==' `
eth0InOld=$(echo $eth0 | awk '{ print $1 }')
eth0OutOld=$(echo $eth0 | awk '{ print $9 }')
eth1InOld=$(echo $eth1 | awk '{ print $1 }')
eth1OutOld=$(echo $eth1 | awk '{ print $9 }')
while true
do
sleep ${1}


eth0=`cat /proc/net/dev | grep eth0 | sed 's=^.*:==' `
eth1=`cat /proc/net/dev | grep eth1 | sed 's=^.*:==' `
timeNew=`date +%s`
eth0InNew=$(echo $eth0 | awk '{ print $1 }')
eth0OutNew=$(echo $eth0 | awk '{ print $9 }')
eth1InNew=$(echo $eth1 | awk '{ print $1 }')
eth1OutNew=$(echo $eth1 | awk '{ print $9 }')
eth0DiffIn=$((eth0InNew-eth0InOld))
eth1DiffIn=$((eth1InNew-eth1InOld))
eth0DiffOut=$((eth0OutNew-eth0OutOld))
eth1DiffOut=$((eth1OutNew-eth1OutOld))
timeDiff=$((timeNew-timeOld))
echo "eht0-In: $((eth0DiffIn*8/1024/timeDiff)) kbps eth0-Out: $((eth0DiffOut*8/1024/timeDiff)) kbps eht1-IN: $((eth1D
iffIn*8/1024/timeDiff)) kbps eth1-Out: $((eth1DiffOut*8/1024/timeDiff)) kbps"
eth0InOld=${eth0InNew}
eth1InOld=${eth1Inew}
eth0OutOld=${eth0OutNew}
eth1OutOld=${eth1OutNew}
timeOld=${timeNew}
done

最新电影 (主页) (邮件) [回复] 20/05/2009, 00:00

你是半年出一次文?

文章真實引用網址:http://blog.luluchina.com/blog/trackback.php?id=162

发表评论

标题

在此添加评论*

称呼*

邮箱地址(可选)

个人主页(可选)



Valid XHTML 1.0 Strict and CSS. Powered by Lifetype 沪ICP备06004858号
Template is designed by calfen, inherited from Template(dabu)designed by Tomex Ou