Archive for December 18th, 2008

写了个监控网络流量的脚本

Thursday, December 18th, 2008

在我们的日常工作当中,监控网络要么使用iptarf,ifstat这些命令实现的,但是需要装额外的RPM包。特别是iptarf装起来麻烦。
我看了下,linux下的/proc/net/dev记录了每块网卡发送和接受的包和字节数。因此萌生想法,写了一个。运行效果:
root@:/root/wt>sh  aa.sh
Current Ip:   inet addr:10.0.65.52 Bcast:10.0.65.255 Mask:255.255.255.0
Summry info:  RX bytes:2424183819 (2311.8 Mb) TX bytes:3519850565 (3356.7 Mb)
eth0 Receive Bytes: 61147  Packets: 433
eth0 Send Bytes: 86458  Packets: 372
eth0 Receive Bytes: 156051  Packets: 924
eth0 Send Bytes: 230962  Packets: 877
eth0 Receive Bytes: 192537  Packets: 1118
eth0 Send Bytes: 283893  Packets: 1073
具体脚本的内容如下,几乎不需要修改,就可以拿到任何机器上去使用了。
root@:/root/wt>cat aa.sh
#! /bin/bash
#Author: Vogts WangTao 2008-12-18
#Get summry info
echo “Current Ip:  [...]

DBA