2009-02-10

MRTG配置笔记

mrtg官方网站:http://oss.oetiker.ch/mrtg/index.en.html

http://www.sunfreeware.com/下载for solaris9 sprac的版本,直接pkgadd进
行安装。
mrtg同时需要libgcc、perl、apache、net-snmp等软件支持。

【mrtg安装配置步骤】
1、安装mrtg
pkgadd -d mrtg-2.16.2-sol9-sparc-local

2、建立mrtg工作目录
mkdir /export/home/gdau/mrtg_test

3、配置apache的httpd.conf
vi /etc/apache/httpd.conf,增加:
-------------------------------------------------------------------
Alias /cmnet/ "/export/home/gdau/mrtg_test/"
<Directory "/export/home/gdau/mrtg">
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
-------------------------------------------------------------------

4、启动apache
/etc/init.d/apache start、stop、restart

5、生成mrtg.cfg文件
perl /usr/local/mrtg-2/bin/cfgmaker --global "WorkDir:
/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E"
--global "options[_]: growright,bits" --ifdesc=alias
--snmp-options=:::::2 ChinaMobile_Manager_Read@221.130.208.50 --output
/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/mrtg.cfg


6、进行采集
perl /usr/local/mrtg-2/bin/mrtg
/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/mrtg.cfg

首次运行会报错,运行三次以上便可以消除错误。

7、生成网页首页文件
perl /usr/local/mrtg-2/bin/indexmaker
--output=/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/index.html
--title=CMNET
/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/mrtg.cfg

8、将采集命令放置crontab,最小粒度为5分钟运行。

以下为:自动生成mrtg.cfg配置文件和自动采集shell脚本
-------------------------------------------------------------------
cmnet_flow_mrtg_cfg.sh
-------------------------------------------------------------------
#!/bin/bash

declare -a ip=(218.204.25.245 218.204.25.237 218.204.25.246
211.138.253.254 218.204.25.240 218.204.25.241 211.138.253.249
218.204.25.238 218.204.25.239 218.204.25.254 218.204.26.254
218.204.25.253 218.204.32.254 218.204.25.252 218.204.38.254
218.204.38.226 218.204.25.251 218.204.44.254 218.204.25.250
218.204.50.254 218.204.25.249 218.204.56.254 218.204.25.248 218.204.60.254 )
declare -a host=(GXNN-PB-CMNET-RT01-NEW-RE0 GXNN-PB-CMNET-RT02
OLD-PB-CMNET-RT02 GXNN-PA-CMNET-RT01 GXNN-PA-CMNET-RT04
GXNN-PA-CMNET-RT05 GXNN-PA-CMNET-RT06 GXNN-PA-CMNET-RT07
GXNN-PA-CMNET-RT08 GXLZ-PB-CMNET-RT01 GXLZ-PB-CMNET-RT02.gx.cnmobile.net
GXGL-PB-CMNET-RT01 GXGL-PB-CMNET-RT02 GXYL-PB-CMNET-RT01
GXYL-PB-CMNET-RT02.gx.cnmobile.net GXYL-PA-CMNET-SW01 GXWZ-PB-CMNET-RT01
GXWZ-PB-CMNET-RT02.gx.cnmobile.net GXBH-PB-CMNET-RT01
GXBH-PB-CMNET-RT02.gx.cnmobile.net GXHC-PB-CMNET-RT01
GXHC-PB-CMNET-RT02.gx.cnmobile.net GXBS-PB-CMNET-RT01 GXBS-PB-CMNET-RT02)
declare -a snmp_c=(GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008)

ip_count=23
host_count=23
snmp_c_count=23
i=0

#生成html前半部
mkdir -p /export/home/gdau/mrtg_test
cd /export/home/gdau/mrtg_test

while [ $i -le $ip_count ]
do
mkdir -p /export/home/gdau/mrtg_test/${ip[$i]}__${host[$i]}
workdir="/export/home/gdau/mrtg_test/${ip[$i]}__${host[$i]}"
output="/export/home/gdau/mrtg_test/${ip[$i]}__${host[$i]}/mrtg.cfg"
snmphost="${snmp_c[$i]}@${ip[$i]}"
perl /usr/local/mrtg-2/bin/cfgmaker --global "WorkDir: $workdir"
--output $output --global "options[_]: growright,bits" --ifdesc=alias
--snmp-options=:::::2 $snmphost

i=$(( $i+1 ))
done

#invoke gather_mrtg_data java program
cd /export/home/gdau/task/gather_mrtg_data
./run_gather_cfg.sh
-------------------------------------------------------------------


-------------------------------------------------------------------
cmnet_flow_mrtg.sh
-------------------------------------------------------------------
#!/bin/bash

declare -a ip=(218.204.25.245 218.204.25.237 218.204.25.246
211.138.253.254 218.204.25.240 218.204.25.241 211.138.253.249
218.204.25.238 218.204.25.239 218.204.25.254 218.204.26.254
218.204.25.253 218.204.32.254 218.204.25.252 218.204.38.254
218.204.38.226 218.204.25.251 218.204.44.254 218.204.25.250
218.204.50.254 218.204.25.249 218.204.56.254 218.204.25.248 218.204.60.254 )
declare -a host=(GXNN-PB-CMNET-RT01-NEW-RE0 GXNN-PB-CMNET-RT02
OLD-PB-CMNET-RT02 GXNN-PA-CMNET-RT01 GXNN-PA-CMNET-RT04
GXNN-PA-CMNET-RT05 GXNN-PA-CMNET-RT06 GXNN-PA-CMNET-RT07
GXNN-PA-CMNET-RT08 GXLZ-PB-CMNET-RT01 GXLZ-PB-CMNET-RT02.gx.cnmobile.net
GXGL-PB-CMNET-RT01 GXGL-PB-CMNET-RT02 GXYL-PB-CMNET-RT01
GXYL-PB-CMNET-RT02.gx.cnmobile.net GXYL-PA-CMNET-SW01 GXWZ-PB-CMNET-RT01
GXWZ-PB-CMNET-RT02.gx.cnmobile.net GXBH-PB-CMNET-RT01
GXBH-PB-CMNET-RT02.gx.cnmobile.net GXHC-PB-CMNET-RT01
GXHC-PB-CMNET-RT02.gx.cnmobile.net GXBS-PB-CMNET-RT01 GXBS-PB-CMNET-RT02)
declare -a snmp_c=(GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008
GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008 GXMCC_cmnet_nm2008)

ip_count=23
host_count=23
snmp_c_count=23
i=0

#生成html前半部
mkdir -p /export/home/gdau/mrtg_test
cd /export/home/gdau/mrtg_test

#echo "<HTML>" > /export/home/gdau/mrtg_test/index.html
#echo "<HEAD>" >> /export/home/gdau/mrtg_test/index.html
#echo " <TITLE>CMNET</TITLE>" >> /export/home/gdau/mrtg_test/index.html
#echo " <meta http-equiv=\"content-type\" content=\"text/html;
charset=iso-8859-15\" >" >> /export/home/gdau/mrtg_test/index.html
#echo " <META NAME=\"Command-Line\"
CONTENT=\"/usr/local/mrtg-2/bin/indexmaker
--output=/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/index.html
--title=CMNET
/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/mrtg.cfg\"
>" >> /export/home/gdau/mrtg_test/index.html
#echo " <META HTTP-EQUIV=\"Refresh\" CONTENT=\"300\" >" >>
/export/home/gdau/mrtg_test/index.html
#echo " <META HTTP-EQUIV=\"Cache-Control\" content=\"no-cache\" >" >>
/export/home/gdau/mrtg_test/index.html
#echo " <META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\" >" >>
/export/home/gdau/mrtg_test/index.html
#echo " <META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 22 Jan 2009 05:57:01
GMT\" >" >> /export/home/gdau/mrtg_test/index.html
#echo " <LINK HREF=\"favicon.ico\" rel=\"shortcut icon\" > " >>
/export/home/gdau/mrtg_test/index.html
#echo "<style type=\"text/css\">" >> /export/home/gdau/mrtg_test/index.html
#echo "/* commandline was: /usr/local/mrtg-2/bin/indexmaker
--output=/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/index.html
--title=CMNET
/export/home/gdau/mrtg_test/221.130.208.50__GXNN-BC-SXNET-RT01-NE80E/mrtg.cfg
*/" >> /export/home/gdau/mrtg_test/index.html
#echo "/* sorry, no style, just abusing this to place the commandline
and pass validation */" >> /export/home/gdau/mrtg_test/index.html
#echo "</style>" >> /export/home/gdau/mrtg_test/index.html
#echo "</HEAD>" >> /export/home/gdau/mrtg_test/index.html
#echo "<BODY bgcolor=\"#ffffff\" text=\"#000000\" link=\"#000000\"
vlink=\"#000000\" alink=\"#000000\">" >>
/export/home/gdau/mrtg_test/index.html
#echo "<H1>CMNET</H1>" >> /export/home/gdau/mrtg_test/index.html
#echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10>" >>
/export/home/gdau/mrtg_test/index.html
#echo "<tr>" >> /export/home/gdau/mrtg_test/index.html
#echo "<td>" >> /export/home/gdau/mrtg_test/index.html


while [ $i -le $ip_count ]
do
mkdir -p /export/home/gdau/mrtg_test/${ip[$i]}__${host[$i]}
workdir="/export/home/gdau/mrtg_test/${ip[$i]}__${host[$i]}"
output="/export/home/gdau/mrtg_test/${ip[$i]}__${host[$i]}/mrtg.cfg"
snmphost="${snmp_c[$i]}@${ip[$i]}"
#perl /usr/local/mrtg-2/bin/cfgmaker --global "WorkDir: $workdir"
--output $output --global "options[_]: growright,bits" --ifref=ip
--ifdesc=alias --snmp-options=::1:1::2 $snmphost
perl /usr/local/mrtg-2/bin/mrtg $output
index="$workdir/index.html"
perl /usr/local/mrtg-2/bin/indexmaker --output=$index --title=CMNET $output

# #生成html中部
# echo "<DIV><B><A
HREF="./${ip[$i]}__${host[$i]}/index.html">${host[$i]}</A></B><BR></DIV>"
>> /export/home/gdau/mrtg_test/index.html
# echo "<br>" >> /export/home/gdau/mrtg_test/index.html

i=$(( $i+1 ))
done

#生成html后半部
#echo "</td>" >> /export/home/gdau/mrtg_test/index.html
#echo "</tr>" >> /export/home/gdau/mrtg_test/index.html
#echo "</TABLE>" >> /export/home/gdau/mrtg_test/index.html
#
#echo "<BR>" >> /export/home/gdau/mrtg_test/index.html
#echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>" >>
/export/home/gdau/mrtg_test/index.html
#echo " <TR>" >> /export/home/gdau/mrtg_test/index.html
#echo " <TD WIDTH=63><A" >> /export/home/gdau/mrtg_test/index.html
#echo " HREF=\"http://oss.oetiker.ch/mrtg/\"><IMG" >>
/export/home/gdau/mrtg_test/index.html
#echo " BORDER=0 SRC=\"mrtg-l.png\" WIDTH=63 HEIGHT=25
ALT=\"MRTG\"></A></TD>" >> /export/home/gdau/mrtg_test/index.html
#echo " <TD WIDTH=25><A" >> /export/home/gdau/mrtg_test/index.html
#echo " HREF=\"http://oss.oetiker.ch/mrtg/\"><IMG" >>
/export/home/gdau/mrtg_test/index.html
#echo " BORDER=0 SRC=\"mrtg-m.png\" WIDTH=25 HEIGHT=25
ALT=\"\"></A></TD>" >> /export/home/gdau/mrtg_test/index.html
#echo " <TD WIDTH=388><A" >> /export/home/gdau/mrtg_test/index.html
#echo " HREF=\"http://oss.oetiker.ch/mrtg/\"><IMG" >>
/export/home/gdau/mrtg_test/index.html
#echo " BORDER=0 SRC=\"mrtg-r.png\" WIDTH=388 HEIGHT=25" >>
/export/home/gdau/mrtg_test/index.html
#echo " ALT=\"Multi Router Traffic Grapher\"></A></TD>" >>
/export/home/gdau/mrtg_test/index.html
#echo " </TR>" >> /export/home/gdau/mrtg_test/index.html
#echo "</TABLE>" >> /export/home/gdau/mrtg_test/index.html
#echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>" >>
/export/home/gdau/mrtg_test/index.html
#echo " <TR VALIGN=top>" >> /export/home/gdau/mrtg_test/index.html
#echo " <TD WIDTH=88 ALIGN=RIGHT><FONT FACE=\"Arial,Helvetica\" SIZE=2>"
>> /export/home/gdau/mrtg_test/index.html
#echo " version 2.16.2</FONT></TD>" >>
/export/home/gdau/mrtg_test/index.html
#echo " <TD WIDTH=388 ALIGN=RIGHT><FONT FACE=\"Arial,Helvetica\"
SIZE=2>" >> /export/home/gdau/mrtg_test/index.html
#echo " <A HREF=\"http://tobi.oetiker.ch/\">Tobias Oetiker</A>" >>
/export/home/gdau/mrtg_test/index.html
#echo " <A
HREF=\"mailto:tobi+mrtglink@oetiker.ch\">&lt;tobi@oetiker.ch&gt;</A>" >>
/export/home/gdau/mrtg_test/index.html
#echo " and&nbsp;<A
HREF=\"http://www.bungi.com/\">Dave&nbsp;Rand</A>&nbsp;<A
HREF=\"mailto:dlr@bungi.com\">&lt;dlr@bungi.com&gt;</A></FONT>" >>
/export/home/gdau/mrtg_test/index.html
#echo " </TD>" >> /export/home/gdau/mrtg_test/index.html
#echo "</TR>" >> /export/home/gdau/mrtg_test/index.html
#echo "</TABLE>" >> /export/home/gdau/mrtg_test/index.html
#echo "</BODY>" >> /export/home/gdau/mrtg_test/index.html
#echo "</HTML>" >> /export/home/gdau/mrtg_test/index.html

#invoke gather_mrtg_data java program
cd /export/home/gdau/task/gather_mrtg_data
./run_gather_data.sh
-------------------------------------------------------------------

-------------------------------------------------------------------
crontab文件
-------------------------------------------------------------------
0,5,10,15,20,25,30,35,40,45,50,55 * * * *
/export/home/gdau/task/cmnet_flow_mrtg.sh
#3 0,1,2 * * * /export/home/gdau/task/cmnet_flow_mrtg_cfg.sh
-------------------------------------------------------------------


【存在问题】
1、mrtg对大流量端口不支持。mrtg默认针对ifTable进行采集,采集的ifIn和
ifOut都为32位。但是针对高速端口,流速很大,32位的Counter很容易溢出。必须
要配置snmp V2版本支持才行。原理是使用ifXTable中的ifHCIn和ifHCOut来采集。
在生成mrtg.cfg文件时,增加:--snmp-options=:::::2选项
由于mrtg(版本:2.16.2)本身存在bug,需要修改cfgmaker脚本的907行。将:
if(not $speed or $counter eq "" or $counter =~ /\D/ or
$SNMP_Session::errmsg or $Net_SNMP_util::ErrorMessage){
修改为:
if(not $speed or $counter eq "" or $counter !~ /\d/ or
$SNMP_Session::errmsg or $Net_SNMP_util::ErrorMessage){
目的是禁止在mrtg.cfg文件中生成noHC:yes的选项。

2、对华为的设备,不支持采集ifAlias。
修改cfgmaker文件,修改:173行。将:
if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
$routers->{$router}{deviceinfo}{sysDescr} =~ m/Version\s+(\d+\.\d+)/) {
push @Variables, ($1 > 11.0 or $1 < 10.0 ) ? "ifAlias" : "CiscolocIfDescr";
if ($1 > 11.2) {push @Variables, "vmVlan";};
if ($1 > 11.3) {push @Variables, "vlanTrunkPortDynamicStatus";};
} elsif ( $routers->{$router}{deviceinfo}{Vendor} =~
/(?:hp|juniper|foundry|dellLan|force10|3com|extremenetworks)/) {
push @Variables, "ifAlias";
}
修改为:
if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
$routers->{$router}{deviceinfo}{sysDescr} =~ m/Version\s+(\d+\.\d+)/) {
push @Variables, ($1 > 11.0 or $1 < 10.0 ) ? "ifAlias" : "CiscolocIfDescr";
if ($1 > 11.2) {push @Variables, "vmVlan";};
if ($1 > 11.3) {push @Variables, "vlanTrunkPortDynamicStatus";};
} elsif ( $routers->{$router}{deviceinfo}{Vendor} =~
/(?:hp|juniper|foundry|dellLan|force10|3com|extremenetworks)/) {
push @Variables, "ifAlias";
} else {
push @Variables, "ifAlias";
}

10 条评论:

匿名 说...

Today, while I was at work, my cousin stole my iphone
and tested to see if it can survive a 30 foot drop, just so she can be a youtube sensation.
My iPad is now broken and she has 83 views. I know this is
entirely off topic but I had to share it with
someone!
Here is my website ... secure online casino

匿名 说...

Was diagnosed with lupus will vary from mild to serious infectionsAnxiety and depression can be complicated with lupus to explore various ways to better understand how this has come.
Elderly-onset lupus, such as skin or blood
test results came back from his lupus, and safe. Em 2 Anos: J podia descer e subir
escadas, anda, sobe e desce escadas, anda,
corre, Faz exerccios na academia com pesos, sobe e desse escadas, anda a vontade
de viver. It's not pressure cooker.
my site: lupus doctor Gays Mills

匿名 说...

Read more about the mechanics of a pinched nerve, or doing nothing didn't miraculously heal you. There are a number of newer metal alloys, technology improved and also allow irritation to the moods, which really traction. Osteoporosis is defined as chronic nerve pain. With time, sometimes accompanied by numbness, tingling and pains. One of the spine, and positioned downward from there, possibly for years.

Here is my weblog ... Leon Junction acupuncture back pain
Here is my web-site - Leon Junction acupuncture back pain

匿名 说...

In improver to eating more cholesterol lowering foods, elders
had reached higher ages, 80, 90 or even 100.

my blog medication cholesterol For high treatment

匿名 说...

To make blogging work for you, you mustiness set
about with Koke by teasing him with his gait and drop.
Samsung introduced a new Samsung pick up close to the other
category members, the arenas are likewise a Groovy
topographic point to estrange family unit members.


Here is my blog ... click here
My site :: click here

匿名 说...

Other than scripted articles, Blogging now to ads that don't place the companionship. By utilizing privacy controls you can create a secure way to already a successful corner blogger and has been through the treat on their own.

my web-site click here

匿名 说...

handle Book is on mitt for the goings-on: Michael J. de la Merced will be
bouncy blogging the for companies deficient to attain the female consumer in their butt audiences.


Check out my web page; click here

匿名 说...

The impression of videoblogging Napster register-sharing service, these
topics motionless pertain a nerve. Target your own recession
seemed to be defined by low outturn. There are several businesses on
main Street including a pair of hotels, restaurants, and shops, yet to try it now.


Look into my site; click here

匿名 说...

Нighly descriрtivе blog, I liked that bit.
Wіll there be a рart 2?

Feеl freе to visit my website - HomePage
My site :: www.magnetspheres.com

匿名 说...

Τhanks for ones marvelous posting! Ι actually enjoyeԁ reading it, yοu're a great author.I will be sure to bookmark your blog and will often come back in the future. I want to encourage you to ultimately continue your great work, have a nice evening!

my web site - Red Kings Poker Bonus :: ::