在UNIX下有很多优秀的流量监控软件,今天我们在这里要说的是用bandwidthd监控你的网络,把bandwidthd安装在网关上可以监控到你整个网络中每个IP的流量,而且可以用曲线图显示各个协议,例如包含http,tcp,udp,icmp,vpn以及p2p协议的流量,以IP为单位.默认的颜色,TCP为绿色;HTTP为蓝色;FTP为浅蓝;P2P为粉红;UDP为棕褐色; ICMP为红色。
1,安装:
更新ports后,
cd /usr/ports/net-mgmt/bandwidthd/
make install
Make clean
装好了。
2,配制
在你的web下建立一个叫bandwidth的目录,
进入到web目录/bandwidth/
#Ln –s /usr/local/bandwidth/htdocs info
用ll命令察看下
应该会看到bandwidthd -> /usr/local/bandwidthd/htdocs
然后进入到
Cd /usr/local/bandwidthd/etc/
Mv bandwidthd.conf-dist bandwidthd.conf
修改配置信息:
ee /usr/local/bandwidthd/etc/bandwidthd.conf
一般修改一下网段和掩码,其他的用默认值即可,如果你熟悉英文,就看看其他选项.大概如下
编辑:
/usr/local/bandwidthd/etc/bandwidthd.conf
####################################################
# Bandwidthd.conf
# Commented out options are here to provide
# documentation and represent defaults
# Subnets to collect statistics on. Traffic that
# matches none of these subnets will be ignored.
# Syntax is either IP Subnet Mask or CIDR
#subnet
subnet 192.168.0.0 255.255.255.0
#subnet 172.16.0.0/12
# Device to listen on
# Bandwidthd listens on the first device it detects
# by default. Run "bandwidthd -l" for a list of
# devices.
dev "xl0" # 把xl0改为相应的内网卡
###################################################
# Options that don't usually get changed
# An interval is 2.5 minutes, this is how many
# intervals to skip before doing a graphing run
skip_intervals 1 # 刷新的时间
# Graph cutoff is how many k must be transfered by an
# ip before we bother to graph it
graph_cutoff 1024 #1024K以上才有图形
#Put interface in promiscuous mode to score to traffic
#that may not be routing through the host machine.
#promiscuous true #让网卡在混杂模式中记录
#Log data to cdf file htdocs/log.cdf
output_cdf true #在bandwidthd中生成log2.cdf log.cdf格式数据记录
#Read back the cdf file on startup
recover_cdf true #在启动bandwidth时重新读取cdf的数据
#Libpcap format filter string used to control what bandwidthd see's
#Please always include "ip" in the string to avoid strange problems
filter "ip" #以IP为过滤对象
#Draw Graphs - This default to true to graph the traffic bandwidthd is recording
#Usually set this to false if you only want cdf output or
#you are using the database output option. Bandwidthd will use very little
#ram and cpu if this is set to false.
graph true
#Set META REFRESH seconds (default 150, use 0 to disable).
#meta_refresh 150
运行:
mv /usr/local/etc/rc.d/bandwidthd.sh.sample /usr/local/etc/rc.d/bandwidthd.sh
启动
/usr/local/etc/rc.d/bandwidthd.sh start
以后server启动后,会自动启动 bandwidthd进程。
ps -all后会看到p1 0:00.10 ./bandwidthd 说明进程已经起来了
过几分钟后,打开
http://服务器ip/bandwidth/info/
就可以看到统计结果了。



