修改RRDStats 监控ip流量
因为本地电信开始要禁止共享宽带,所以最近使用防尖兵版的Coyote来作路由。Coyote上dolly 制作的RRDStats可以监控QOS类的流量,但根据他主页的说明,必需使用他的脚本。我是仿照台湾LINUX_XP作的QOS,限制每家人ip流量(家庭使用),所以无法在RRD上监测到各家的流量。怎么办呢?经过几天的实验,修改dolly原有脚本,终于取得成功了。
http://www.picd.net/data/2006/10/15/22/M_BXX5W811609220051.JPG
-----------------------------------------------------------------------------------------------
我的QOS设置中的一段:
# 192.168.0.21使用 10 |192.168.0.22使用 20 |192.168.0.23使用 30
………………………
.# 由于采用 fw 过滤器,所以此处使用 pfifo 的队列规则即可
tc qdisc add dev eth1 parent 10:10 handle 101: pfifo
tc qdisc add dev eth1 parent 10:20 handle 102: pfifo
tc qdisc add dev eth1 parent 10:30 handle 103: pfifo
------------------------------------------------------------------------------------------------------
1.不启用Coyote自带的QOS控制脚本,因为它和我无关。
2.在RRDStats package页面,启用QOS tracking enabled,使其开机后启动RRD QOS.
3.修改文件:
3.1 ------------------------------------------------------------------------------------------------------------------------------------------------------------------
修改/etc/rrd.config,在/etc/rrd.config中查找
create_qos_sources () {
# create_qos_database "qos_110.rrd"
return
}
改为:
create_qos_sources () {
create_qos_database "qos_110.rrd"
create_qos_database "qos_120.rrd"
create_qos_database "qos_130.rrd"
return
}
# 创建名为dqos_110.rrd等等数据库。数据库的名字可以自己随便起。
寻找:
query_qos_sources () {
# fetch_qos "1:10" "qos_110.rrd"
return
}
改为
query_qos_sources () {
fetch_qos "1:101" "qos_110.rrd"
fetch_qos "1:102" "qos_120.rrd"
fetch_qos "1:103" "qos_130.rrd"return
}
在fetch_qos后面改为你QOS中设置的pfifo编号,不要搞错。这fetch_qos "1:101" "qos_110.rrd"对应的是我的脚本中tc qdisc add dev eth1 parent 10:10 handle 101: pfifo。101对应101: pfifo。这和我后面提取数据值的设置有关。
如果你的QOS脚本设置不是这样的,请用命令tc -s qdisc show dev eth0查看。(eth0是你的网卡。)
可以看见如下信息:
qdisc pfifo 101: parent 10:10
Sent 27444 bytes 456 pkts (dropped 0, overlimits 0)
取qdisc pfifo后的值,其对应的类为10:10。
3.2-------------------------------------------------------------------------------------------------------
修改\var\rrd\script\rrd.create文件(创建数据库文件)
查找如下内容:
# Creates RRD database for QOS datasource
create_qos_database () {
local valid=$(($RRD_QOS_UPDATEINTERVAL*2))
$RRD create ${RRD_DBDIR}${1} --step $RRD_QOS_UPDATEINTERVAL \
DS:pr0:COUNTER:${valid}:0:${RRD_MAX_DOWNSTREAM} \
DS:pr1:COUNTER:${valid}:0:${RRD_MAX_DOWNSTREAM} \
DS:pr2:COUNTER:${valid}:0:${RRD_MAX_DOWNSTREAM} \
DS:pr0u:COUNTER:${valid}:0:${RRD_MAX_UPSTREAM} \
DS:pr1u:COUNTER:${valid}:0:${RRD_MAX_UPSTREAM} \
DS:pr2u:COUNTER:${valid}:0:${RRD_MAX_UPSTREAM} \
RRA:AVERAGE:0.5:1:120 \
RRA:AVERAGE:0.5:3:320 \
RRA:AVERAGE:0.5:10:288
echo " - qos_${1} QOS classes statistics database created."
echo " - update interval: $RRD_QOS_UPDATEINTERVAL sec"
echo " - max downstream $((${RRD_MAX_DOWNSTREAM}/1024)) kB/s, max upstream $((${RRD_MAX_UPSTREAM}/1024)) kB/s"
修改为:
#创建qos rrd数据库
create_qos_database () {
local valid=$(($RRD_QOS_UPDATEINTERVAL*2))
$RRD create ${RRD_DBDIR}${1} --step $RRD_QOS_UPDATEINTERVAL \
DS:in:COUNTER:${valid}:0:${RRD_MAX_DOWNSTREAM} \
DS:out:COUNTER:${valid}:0:${RRD_MAX_UPSTREAM} \
RRA:AVERAGE:0.5:1:360 \
RRA:AVERAGE:0.5:15:576 \
RRA:AVERAGE:0.5:90:672 \
RRA:AVERAGE:0.5:360:744
echo " - qos_${1} QOS classes statistics database created."
echo " - update interval: $RRD_QOS_UPDATEINTERVAL sec"
echo " - max downstream $((${RRD_MAX_DOWNSTREAM}/1024)) kB/s, max upstream $((${RRD_MAX_UPSTREAM}/1024)) kB/s"
# 这些设置创建索采集数据的值、时间等等。
3.3---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
修改\var\rrd\script\rrd.update.qos文件(采集数据文件)
全部改为如下
#!/bin/sh
. /etc/rrd.config
# reads QOS counters and saves to rrd
# 1-rootcls 2-dbname
fetch_qos () {
subclasspart=`echo ${1} | cut -f2 -d':'`
outbytes=`tc -s qdisc show dev ppp0 | sed -n -e "/o ${subclasspart}:/{n;p;}" | cut -f3 -d' '`
inbytes=`tc -s qdisc show dev eth0 | sed -n -e "/o ${subclasspart}:/{n;p;}" | cut -f3 -d' '`
# echo "Debug QOS ${2} inb:$inbytes outb:$outbytes"
$RRD update ${RRD_DBDIR}${2} N:$inbytes:$outbytes
}
# 我是adsl拨号,所以上行是ppp0,如果是固定ip请用你外网卡名.
3.4---------------------------------------------------------------------------------------------------------------------------------------------------------------------
修改\var\rrd\www\templates文件(画图文件)
全部改为如下:
<RRD::GRAPH img/qos_<RRD::TPL::PARAM 5>_<RRD::TPL::PARAM 1>.png
--title=" <RRD::TPL::PARAM 6>, last <RRD::TPL::PARAM 2>"
--imginfo '<img src="img/%s?nc=%lu" width="%lu" height="%lu" alt="last <RRD::TPL::PARAM 2>" />'
--start <RRD::TPL::PARAM 3> --end <RRD::TPL::PARAM 4>
--vertical-label Kbytes
--width 500 --height 200
--upper-limit 256
--lower-limit 0
--imgformat PNG
--rigid
--lazy
DEF:in=/var/rrd/data/<RRD::TPL::PARAM 5>.rrd:in:AVERAGE
DEF:out=/var/rrd/data/<RRD::TPL::PARAM 5>.rrd:out:AVERAGE
CDEF:inkbps=in,1024,/
CDEF:outkbps=out,1024,/
COMMENT:" "
AREA:inkbps#00cc00:"IN "
GPRINT:inkbps:MIN:"Min\: %6.2lf Kb"
GPRINT:inkbps:AVERAGE:"Average\: %6.2lf Kb"
GPRINT:inkbps:MAX:"Max\: %6.2lf kb"
GPRINT:inkbps:LAST:"Current\: %6.2lf kb\n"
COMMENT:" "
LINE1:inkbps#008800:""
LINE2:outkbps#0000cc:"OUT"
GPRINT:outkbps:MIN:" %6.2lf kb"
GPRINT:outkbps:AVERAGE:" %6.2lf kb"
GPRINT:outkbps:MAX:" %6.2lf kb"
GPRINT:outkbps:LAST:" %6.2lf kb\n"
>
3.5---------------------------------------------------------------------------------------------------------------------------------------------------------------------
修改/var/rrd/www/index.cgi
找到如下段
<!--
To enable QOS, uncomment next <RRD:INCLUDE...> tags (remove # from definition
and also remove HTML comment tags. First parameter is database name (without
.rrd suffix), second is caption displayd in graphs.
-->
在其下添加
<RRD::INCLUDE templates/qos_<RRD::CV type>.inc "qos_110" "xxxx1">
<RRD::INCLUDE templates/qos_<RRD::CV type>.inc "qos_120" "xxxx2">
<RRD::INCLUDE templates/qos_<RRD::CV type>.inc "qos_150" "xxxx3">
# Xxxx1为你所想用的名字,会显示在图片上,应为英文。否则图片上显示为乱码。
3.6----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
修改/var/rrd/www/include /menu.inc找到如下内容
<!--
To enable QOS statistics, edit and uncomment next lines. Parameter rrd specifies
QOS RRD database name without .rrd suffix. Parameter caption specifies graph
caption.
-->
在其下添加
<a class="submenuitem" href="qos_specific.cgi?rrd=qos_130&caption= xxxx1">xxxx1</a><br />
<a class="submenuitem" href="qos_specific.cgi?rrd=qos_140&caption=xxxx2">xxxx2</a><br />
<a class="submenuitem" href="qos_specific.cgi?rrd=qos_150&caption=xxxx3">xxxx3</a><br />
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4.保存------重启计算机。
还可以修改为只生成一个数据库文件,将所采集的数据全部画在一张图上等等。大家可以自行试验。
页:
[1]