一、实验环境

参考教程:​​http://www.netmon.org/dummies.htm​

​http://www.docin.com/p-158415185.html​

MRTG中文手册:​​http://bbs.chinaunix.net/thread-1344687-1-1.html​

​http://www.enterastream.com/whitepapers/mrtg/mrtg-manual-cap9.html​

1.硬件平台

vmware workstation 8.05

Guest OS: 64bit windows server 2008 R2 SP1中文标准版-内存1GB

Host OS: 64bit windows 7 中文Home版

内存6GB

CPU:i5-2450m

2.所需软件

A. MRTG:

下载地址:​​http://oss.oetiker.ch/mrtg/pub/?M=D​

版本:2.17.4

B.ActivePerl

下载地址:​​http://www.activestate.com/activeperl/downloads​

版本:64bit 5.16.3

C.Microsoft® Windows® Server 2003 Resource Kit Tools

下载地址:​​http://www.microsoft.com/en-us/download/details.aspx?id=17657​

3.实验拓扑:

2台虚拟机A和B

A: OS- windows server 2008 R2 作为DC

IP:192.168.190.168

B: OS – windows server 2008 R2 作为域内MRTG主机,用来监控主机A上的流量

IP:192.168.190.194


二、安装过程

1.安装两台VM上OS-略

2.server B加入域-略

3.server B上加入IIS服务器角色。后续步骤如果没注明,都在server B上操作

4..建立以下目录:

c:\inetpub\wwwroot\mrtg -index.html目录

C:\MRTG\mrtg-2.17.4\ -mrtg执行文件目录

C:\MRTG\cfg -配置文件目录

C:\MRTG\reg -注册表存放目录

5.更改IIS默认网站目录为c:\inetpub\wwwroot\mrtg

6.解压MRTG2.17.4到C:\MRTG目录

7.安装ActivePerl.确保安装成功后环境变量增加路径c:\perl64\bin

8.安装windows 2003 Resource Tools.下载安装包,执行安装程序安装到默认路径C:\Program Files (x86)\Windows Resource Kits

9.增加server A上的SNMP功能特性

配置server A上的SNMP服务如下:


10.server B上配置MRTG,首先进入命令行模式(开始->运行->输入CMD)。进入C:\MRTG\mrtg-2.17.4\bin目录。输入如下指令:

10.1、perl cfgmaker ​​public@192.168.190.168 --global​​ "WorkDir: c:\inetpub\wwwroot\mrtg" --output c:\mrtg\cfgmrtg.cfg

(团体名为public,192.168.190.168为DC​​服务器​​的IP,c:\inetpub\wwwroot\mrtg为要生成的网页目录,同时也是在IIS中已经配置好的发布目录,完成该命令后会生成一个名为mrtg.cfg的配置文件)

注意 workdir后面有一个空格

输出:

C:\MRTG\mrtg-2.17.4\bin>perl cfgmaker --ifref=ip --ifdesc=descr --if-filter=$if_is_ethernet public@192.168.190.168

--global "WorkDir: c:\inetpub\wwwroot\mrtg" --output c:\mrtg\cfg\mrtg.cfg

--base: Get Device Info on public@192.168.190.168:

--base: Vendor Id: Unknown Vendor - 1.3.6.1.4.1.311.1.1.3.1.3

--base: Populating confcache

--base: Get Interface Info

--base: Walking ifIndex

--snpd:   public@192.168.190.168: -> 1 -> ifIndex = 1

--snpd:   public@192.168.190.168: -> 2 -> ifIndex = 2

--snpd:   public@192.168.190.168: -> 3 -> ifIndex = 3

--snpd:   public@192.168.190.168: -> 4 -> ifIndex = 4

--snpd:   public@192.168.190.168: -> 5 -> ifIndex = 5

--snpd:   public@192.168.190.168: -> 6 -> ifIndex = 6

--snpd:   public@192.168.190.168: -> 7 -> ifIndex = 7

--snpd:   public@192.168.190.168: -> 8 -> ifIndex = 8

--snpd:   public@192.168.190.168: -> 9 -> ifIndex = 9

--snpd:   public@192.168.190.168: -> 10 -> ifIndex = 10

--snpd:   public@192.168.190.168: -> 11 -> ifIndex = 11

--snpd:   public@192.168.190.168: -> 12 -> ifIndex = 12

--snpd:   public@192.168.190.168: -> 13 -> ifIndex = 13

--snpd:   public@192.168.190.168: -> 14 -> ifIndex = 14

--snpd:   public@192.168.190.168: -> 15 -> ifIndex = 15

--snpd:   public@192.168.190.168: -> 16 -> ifIndex = 16

--snpd:   public@192.168.190.168: -> 17 -> ifIndex = 17

--snpd:   public@192.168.190.168: -> 18 -> ifIndex = 18

--base: Walking ifType

--snpd:   public@192.168.190.168: -> 1 -> ifType = 24

--snpd:   public@192.168.190.168: -> 2 -> ifType = 131

--snpd:   public@192.168.190.168: -> 3 -> ifType = 131

--snpd:   public@192.168.190.168: -> 4 -> ifType = 131

--snpd:   public@192.168.190.168: -> 5 -> ifType = 23

--snpd:   public@192.168.190.168: -> 6 -> ifType = 6

--snpd:   public@192.168.190.168: -> 7 -> ifType = 6

--snpd:   public@192.168.190.168: -> 8 -> ifType = 6

--snpd:   public@192.168.190.168: -> 9 -> ifType = 23

--snpd:   public@192.168.190.168: -> 10 -> ifType = 131

--snpd:   public@192.168.190.168: -> 11 -> ifType = 131

--snpd:   public@192.168.190.168: -> 12 -> ifType = 6

--snpd:   public@192.168.190.168: -> 13 -> ifType = 131

--snpd:   public@192.168.190.168: -> 14 -> ifType = 6

--snpd:   public@192.168.190.168: -> 15 -> ifType = 6

--snpd:   public@192.168.190.168: -> 16 -> ifType = 6

--snpd:   public@192.168.190.168: -> 17 -> ifType = 6

--snpd:   public@192.168.190.168: -> 18 -> ifType = 6

--base: Walking ifAdminStatus

--snpd:   public@192.168.190.168: -> 1 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 2 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 3 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 4 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 5 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 6 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 7 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 8 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 9 -> ifAdminStatus = 2

--snpd:   public@192.168.190.168: -> 10 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 11 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 12 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 13 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 14 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 15 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 16 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 17 -> ifAdminStatus = 1

--snpd:   public@192.168.190.168: -> 18 -> ifAdminStatus = 1

--base: Walking ifOperStatus

--snpd:   public@192.168.190.168: -> 1 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 2 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 3 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 4 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 5 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 6 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 7 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 8 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 9 -> ifOperStatus = 6

--snpd:   public@192.168.190.168: -> 10 -> ifOperStatus = 2

--snpd:   public@192.168.190.168: -> 11 -> ifOperStatus = 2

--snpd:   public@192.168.190.168: -> 12 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 13 -> ifOperStatus = 2

--snpd:   public@192.168.190.168: -> 14 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 15 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 16 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 17 -> ifOperStatus = 1

--snpd:   public@192.168.190.168: -> 18 -> ifOperStatus = 1

--base: Walking ifMtu

--snpd:   public@192.168.190.168: -> 1 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 2 -> ifMtu = 4091

--snpd:   public@192.168.190.168: -> 3 -> ifMtu = 1460

--snpd:   public@192.168.190.168: -> 4 -> ifMtu = 1464

--snpd:   public@192.168.190.168: -> 5 -> ifMtu = 1494

--snpd:   public@192.168.190.168: -> 6 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 7 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 8 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 9 -> ifMtu = 0

--snpd:   public@192.168.190.168: -> 10 -> ifMtu = 1480

--snpd:   public@192.168.190.168: -> 11 -> ifMtu = 1472

--snpd:   public@192.168.190.168: -> 12 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 13 -> ifMtu = 1280

--snpd:   public@192.168.190.168: -> 14 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 15 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 16 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 17 -> ifMtu = 1500

--snpd:   public@192.168.190.168: -> 18 -> ifMtu = 1500

--base: Walking ifSpeed

--snpd:   public@192.168.190.168: -> 1 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 2 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 3 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 4 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 5 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 6 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 7 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 8 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 9 -> ifSpeed = 0

--snpd:   public@192.168.190.168: -> 10 -> ifSpeed = 0

--snpd:   public@192.168.190.168: -> 11 -> ifSpeed = 100000

--snpd:   public@192.168.190.168: -> 12 -> ifSpeed = 1000000000

--snpd:   public@192.168.190.168: -> 13 -> ifSpeed = 100000

--snpd:   public@192.168.190.168: -> 14 -> ifSpeed = 1000000000

--snpd:   public@192.168.190.168: -> 15 -> ifSpeed = 1000000000

--snpd:   public@192.168.190.168: -> 16 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 17 -> ifSpeed = 1073741824

--snpd:   public@192.168.190.168: -> 18 -> ifSpeed = 1073741824

--base: Writing c:\mrtg\cfg\mrtg.cfg


CFG文件构成:

    10.2、perl indexmaker c:\mrtg\cfg\mrtg.cfg>c:\inetpub\wwwroot\mrtg\index.html

(使用INDEXMAKER将MRTG.CFG文件中的内容转换成index.html,方便我们进行浏览管理。)

    10.3、perl mrtg --logging=c:\mrtg\cfg\mrtg.log c:\mrtg\cfg\mrtg.cfg(从MRTG.CFG中读取配置并启动MRTG程序,同时记录日志信息到mrtg.log中)执行完后就会发现命令行模式开始实时监控。如图:



11.将程序以服务方式进行

step1:将c:\Program Files (x86)\Windows Resource Kits\Tools下instsrv.exe和Srvany.exe复制到mrtg安装目录的BIN目录下。例如c:\mrtg\mrtg-2.17.4\bin。

step2:在MRTG\mrtg-2.17.4\BIN目录下执行instsrv mrtg "c:\mrtg\mrtg-2.17.4\bin\srvany.exe"安装MRTG为系统服务。

    step3:配置SRVANY,在注册表hkey_local_machine\system\currentcontrolset\services\mrtg中添加一个parameters项,再在parameters子键中添加以下项目:

Application的字串值,内容为c:\perl64\bin\wperl.exe  (wperl运行没有命令行控制台窗口)

AppDirectory的字串值,内容为c:\mrtg\mrtg-2.17.4\bin\

AppParameters的字串值,内容为mrtg --logging=c:\mrtg\cfg\mrtg.log c:\mrtg\cfg\mrtg.cfg

或者直接导入如下注册表文件wrtg.reg:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MRTG3\Parameters]

"Application"="c:\\perl64\\bin\\wperl.exe"

"AppParameters"="c:\\mrtg\\mrtg-2.17.4\\bin\\mrtg --logging=c:\\mrtg\\cfg\\eventlog c:\\mrtg\\cfg\\mrtg.cfg"

"AppDirectory"="c:\\mrtg\\mrtg-2.17.4\\bin\\"

step:4: 修改mrtg.cfg文件

添加:

echo RunAsDaemon: yes  >> mrtg.cfg
echo Language: chinese >> mrtg.cfg (可选)

Step5:到服务管理里头配置MRTG服务为自动


12.修改成中文标识:

例如68端口对应的中文名是“外网出口”,则用记事本打开index.htm,通过查找Traffic Analysis for 68将其替换为你所希望的中文名“外网出口”即可。

13.优化步骤10.1 cfgmaker,优化如下:

A:只显示指定的端口

perl cfgmaker --ifref=ip --ifdesc=descr --if-filter=$if_is_ethernet​public@192.168.190.168 --global​​ "WorkDir: c:\inetpub\wwwroot\mrtg" --output c:\mrtg\cfg\mrtg.cfg

修改前页面显示:


修改后:



B:放大图形

修改cfg文件

源文件:

### Interface 12 >> Descr: 'Intel(R)-PRO/1000-MT-Network-Connection' | Name: 'ethernet_5' | Ip: '192.168.190.168' | Eth: 'No Ethernet Id' ###

Target[192.168.190.168_192.168.190.168]: /192.168.190.168:public@192.168.190.168:

SetEnv[192.168.190.168_192.168.190.168]: MRTG_INT_IP="192.168.190.168" MRTG_INT_DESCR="Intel(R)-PRO/1000-MT-Network-Connection"

MaxBytes[192.168.190.168_192.168.190.168]: 125000000

Title[192.168.190.168_192.168.190.168]: Intel(R)-PRO/1000-MT-Network-Connection -- DC1.emmdemo.com

PageTop[192.168.190.168_192.168.190.168]: <h1>Intel(R)-PRO/1000-MT-Network-Connection -- DC1.emmdemo.com</h1>

增加:

Xsize[192.168.190.168_192.168.190.168]: 600

Ysize[192.168.190.168_192.168.190.168]: 100

重新构筑配置文件的批处理程序build.bat:

net stop mrtg3

del /q C:\inetpub\wwwroot\MRTG\*.*

perl cfgmaker public@192.168.190.168 --global "WorkDir: c:\inetpub\wwwroot\mrtg" --output c:\mrtg\cfgmrtg.cfg

perl indexmaker c:\mrtg\cfg\mrtg.cfg>c:\inetpub\wwwroot\mrtg\index.html

net start mrtg3

增加xsize后的效果:


去掉:

Xsize[192.168.190.168_192.168.190.168]: 600

Ysize[192.168.190.168_192.168.190.168]: 100

增加:

XScale[192.168.190.168_192.168.190.168]: 2.0

YScale[192.168.190.168_192.168.190.168]: 2.0

效果如下: