The MRTG 2.17.4 Windows Installation Guide


文档总体思路:

A.软件安装

1.下载并安装activeperl,并确认系统的环境变量中有相关路径。

2.下载并解压MRTG。

B.配置MRTG:

1.创建MRTG的配置文件。相关命令是(这些命令都是在cmd中运行):

perl cfgmaker public@10.10.10.1 --global "WorkDir: c:\www\mrtg" --output mrtg.cfg

2.修改或添加一些必要的参数,特别是关于交换机的参数,文件输出路径(上面的命令中就有)。还有一些有用的参数:


       WorkDir: c:\www\mrtg    //其实在我自己的配置文件中加了这三个命令在文件开头,注意c:前面有个空格

       RunAsDaemon:yes        //让命令每五分钟运行一次,如果要改变时间则可以用下面的命令。Interval.

       Interval:5                          //可以自由设置时间的长度,是分钟数。

C.让MRTG一直运行:

1.一种方法是设置脚本让MRTG开机的时候运行。把脚本放入开始菜单的startup文件夹下。

       cd c:\mrtg-2.17.4\bin

       start /Dc:\mrtg-2.17.4\bin wperl mrtg --logging=eventlog mrtg.cfg

2.第二种方法是将MRTG设置成Windows的服务,可以开机就自动运行。

       instsrv MRTG c:\mrtg\bin\srvany.exe

       regedit /s mrtg.reg

   而mrtg.reg中的内容如下

 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MRTG\Parameters]
 "Application"="c:\\perl\\bin\\wperl.exe"
 "AppParameters"="c:\\mrtg-2.17.4\\bin\\mrtg --logging=eventlog c:\\mrtg-2.17.4\\bin\\mrtg.cfg"
 "AppDirectory"="c:\\mrtg-2.17.4\\bin\\"

D.发布网站,查看结果:

1.使用Indexmaker命令建立一个默认页面,并且把数据定向到默认页面,如下:

   Perl  Indexmaker mrtg.cfg > C:\www\mrgt\Default.htm

2.根据MRTG的输出文件,发布一个网站,通过访问这个网站来动态查看交换机的信息。

3.如果只是本机访问,只需要修改host文件来使设置的域名可访问即可。


MRTG的主要作用是根据配置文件获得交换机的相关信息,并根据这些信息在指定的输出目录中生成一系列的相关的网站文件.

原文出处:http://oss.oetiker.ch/mrtg/doc/mrtg-nt-guide.en.html

SYNOPSIS

Installing MRTG on a Windows box is not quite as "click and point" as some might want it to be. But then again, it is not all that difficult if you follow the instructions below.

PREREQUISITES

To get MRTG to work on Windows you need the following:


  • A current copy of Perl. For Example ActivePerl 5.8.8 from ActiveState http://www.activestate.com/store/activeperl/download/

    //下载activeperl,它是一个脚本解释器

  • The latest version of MRTG from http://oss.oetiker.ch/mrtg/pub. Look for mrtg-2.17.4.zip or better. The archive also contains a precompiled copy of rateup.exe for Win32.
    //下载MRTG

INSTALLING

I suggest you do the following from the machine that will be running MRTG, which, in this case, is also a web server. All examples are for doing things to a LOCAL machine.

First

Unzip MRTG to C:\mrtg-2.17.4 on the Windows machine of your choice.

Next

Install Perl on the same Windows machine. You might want to make sure that the Perl binary directory is listed in your system path.

 C:\Perl\bin;%SystemRoot%\system32;%SystemRoot%;...
//安装activeperl,并检查是否被加到了系统的环境变量里。

You can manually check this by going to [Control Panel]->[System]->[Environment]

To see if everything is installed properly you can open a Command Shell and go into c:\mrtg-2.17.4\bin. Type:

 perl mrtg

This should give you a friendly error message complaining about the missing MRTG configuration file. Now, you have successfully installed MRTG and Perl.

//在DOS界面下,切换到mrtg所在目录,执行以上命令,这是一个测试,测试perl是否已正确按照。


CONFIGURING MRTG

Now it is time to create a configuration for MRTG. But before we begin you need to know a few things. Take an opportunity to gather the following information:

  • The IP address or hostname and the SNMP port number, (if non standard), of the device you want to monitor.

  • If you want to monitor something other than bytes in and out, you must also know the SNMPOID of what you want to monitor.

  • Finally you need to know the read-only SNMP community string for your device. If you don't know it, try public, that is the default.

For the rest of this document we will be using device 10.10.10.1 ( a CISCO Catalyst 5000) with Community string public. We are interested in monitoring traffic, and the CPU load. Let's begin.

The first thing we do in setting up MRTG is making a default config file. Get to a cmd prompt and change to the c:\mrtg-2.17.4\bin directory. Type the following command:

 perl cfgmaker public@10.10.10.1 --global "WorkDir: c:\www\mrtg" --output mrtg.cfg
//这是为mrtg的执行创建一个配置文件,以便执行的时候有依据。cfgmaker是bin目录下的一个命令,可执行程序,作用就是创建配置文件。后面跟的是相关参数,关于路由器的community string,IP address, 这里的community string必须与交换机上的一样,否者无法从交换机上获得相关信息。后面是之后的文件输出目录,参数output是把配置文件命名。

This creates an initial MRTG config file for you. Note that in this file all interfaces of your router will be stored by number. Unfortunately, these numbers are likely to change whenever you reconfigure your router. In order to work around this you can get cfgmaker to produce a configuration which is based on Ip numbers, or even Interface Descriptions. Check cfgmaker

If you get an error message complaining about no such name or no response, your community name is probably wrong.

Now, let's take a look at the mrtg.cfg file that was created.

In Perl, a # is a comment, synonymous with REM in DOS.

Add the following to the top of the mrtg.cfg file:

WorkDir: c:\www\mrtg配置文件中#前面不要有空格,否则会出错,而c:前面是有空格的。

This is where the web pages are created, usually a web root.

 ######################################################################
 # Description: LCP SUWGB
 # Contact: Administrator
 # System Name: LC-Bridge
 # Location: Here
 #.....................................................................

TargetDevice's IP Address:Interface Number:Community:IP Address

 Target[10.10.10.1.1]: 1:public@10.10.10.1

This is the interface speed (Default is 10 megabits; for 100Mbit devices use 12500000 and so on...)

 MaxBytes[10.10.10.1.1]: 1250000

 Title[10.10.10.1.1]: LC-Bridge (sample.device): ether0

This section determines how the web page headers will look

 PageTop[10.10.10.1.1]: <H1>Traffic Analysis for ether0</H1>
  <TABLE>
  <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  <TR><TD>Interface:</TD><TD>ether0(1)</TD></TR>
  <TR><TD>IP:</TD><TD>sample.device(10.10.10.1)</TD></TR>
  <TR><TD>Max Speed:</TD>
  <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  </TABLE>

  Target[10.10.10.1.2]: 2:public@10.10.10.1
  MaxBytes[10.10.10.1.2]: 1250000
  Title[10.10.10.1.2]: LC-Bridge (): ulink0
  PageTop[10.10.10.1.2]: <H1>Traffic Analysis for ulink0</H1>
   <TABLE>
   <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
   <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
   <TR><TD>Interface:</TD><TD>ulink0(2)</TD></TR>
   <TR><TD>IP:</TD><TD>()</TD></TR>
   <TR><TD>Max Speed:</TD>
   <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
   </TABLE>

  #---------------------------------------------------------------

And that's a very basic MRTG config file. You can run this and see your results by going into the c:\mrtg-2.17.4\bin directory and typing:

 perl mrtg mrtg.cfg
// mrtg 是目录下的可执行文件,而mrtg.cfg是刚刚创建的配置文件。命令的作用是让mrtg以mrtg.cfg中的配置运行。

It is normal to get errors for the first two times you run this command. The errors will alert you about the fact that there have not been any log files in existence before.

If you take a look at those web pages they are not very exciting (yet). You need to have the MRTG files run every five minutes to produce the desired results. Just run it again after a few minutes. You should now be able to see the first lines in your graphs.

MAKE MRTG RUN ALL THE TIME

Starting MRTG by hand every time you want to run it is not going to make you happy I guess.

There is a special option you can set in the MRTG configuration file so so that MRTG will not terminate after it was started. Instead it will wait for 5 minutes and then run again.

Add the option

 RunAsDaemon: yes

to your mrtg.cfg file and start it with:

 start /Dc:\mrtg-2.17.4\bin wperl mrtg --logging=eventlog mrtg.cfg

// 也是运行mrtg,只是参数更多,更复杂。是让wperl来控制其运行的。Wperl进程的结束,mrtg才会结束。


If you use wperl instead of perl, no console window will show. MRTG is now running in the background. If it runs into problems it will tell you so over the EventLog. To stop MRTG, open the Task Manager and terminate the wperl.exe process. If mrtg has anything to tell you these messages can be found in the event log.

If you put a shortcut with

 Target:    wperl mrtg --logging=eventlog mrtg.cfg
 Start in:  c:\mrtg-2.17.4\bin

into your start-up folder, MRTG will now start whenever you login to your NT box.

If you do not want to log into your box just to start MRTG. Have a look at http://www.firedaemon.com/mrtg-howto.html which describes a free tool to start any program as a Service. The pages gives specific instructions for MRTG users.

HOW TO SETUP MRTG AS A WINDOWS SERVICE(把MRTG设置成一项服务,可以在开机的时候自动运行,这个过程的实质似乎就是修改相应的注册表项。)

Additional Prerequisites

Preparation

Please complete the following steps before starting the installation:

  • Copy srvany.exe and instsrv.exe to c:\mrtg-2.17.4\bin\ (your MRTG bin directory).

  • Create a file called mrtg.reg anywhere on your system and paste the following content into it:

     Windows Registry Editor Version 5.00
    
    


     [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MRTG\Parameters]
     "Application"="c:\\perl\\bin\\wperl.exe"
     "AppParameters"="c:\\mrtg-2.17.4\\bin\\mrtg --logging=eventlog c:\\mrtg-2.17.4\\bin\\mrtg.cfg"
     "AppDirectory"="c:\\mrtg-2.17.4\\bin\\"
    
    


Service Installation

Once again, assuming that MRTG is already fully installed and configured on the target system under c:\mrtg\ the following steps are necessary to setup MRTG as a service.

Using the command prompt go into the temporary directory where you unzipped the package. When there type the following command to create a service named "MRTG" in the Windows Services management console:

 instsrv MRTG c:\mrtg\bin\srvany.exe

Now you need to create the App* entries required for the new service. You can do this by either right-clicking on the mrtg.reg file and selecting 'merge' or by running the following command:

 regedit /s mrtg.reg

After setting up the registry entry it is time to point it to your MRTG installation. If you have installed MRTG under c:\mrtg\, you can skip this step. Open your registry editor (Start -> Run -> regedt32), and locate the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MRTG] key. Make sure that the ImagePath variable is correctly pointing to srvany.exe located in your MRTG bin directory (for example c:\mrtg\bin\srvany.exe). Next you have to expand the MRTG tree, and go to the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MRTG\Parameters] key. Under Parameters make sure that all the Application variables are setup properly.

At this point you are ready to run the service. The only thing left to do is to start the MRTG service in the Services management console. After you do this, you should see two new processes running on your system: srvany.exe and wperl.exe. Make sure to stop any previously running MRTG processes to avoid conflict.

Note that it is imperative to set the RunAsDaemon: yes option or the service will stop after just one single run!

EXAMPLE

Now lets look at a config file to monitor what we wanted to on our mythical Cisco Cat 5000 -- utilization on ports 3, 5, 10, and 24, and the CPU Load, which will show us nonstandard mrtg configurations as well as more options..

 WorkDir: c:\www\mrtg
 RunAsDaemon: yes

 ######################################################################
 # Description: LCP SUWGB
 # Contact: Administrator
 # System Name: LC-Bridge
 # Location: Here
 #.....................................................................

 Target[10.10.10.1.1]: 3:public@10.10.10.1
 MaxBytes[10.10.10.1.1]: 1250000
 Title[10.10.10.1.1]: LC-Bridge (sample-device): ether0
 PageTop[10.10.10.1.1]: <H1>Traffic Analysis for ether0</H1>
  <TABLE>
 <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
 <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
 <TR><TD>Interface:</TD><TD>ether0(3)</TD></TR>
 <TR><TD>IP:</TD><TD>sample-device(10.10.10.1)</TD></TR>
 <TR><TD>Max Speed:</TD>
 <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
 </TABLE>

 #---------------------------------------------------------------

 Target[10.10.10.1.2]: 5:public@10.10.10.1
 MaxBytes[10.10.10.1.2]: 1250000
 Title[10.10.10.1.2]: LC-Bridge (): ulink0
 PageTop[10.10.10.1.2]: <H1>Traffic Analysis for ulink0</H1>
  <TABLE>
  <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  <TR><TD>Interface:</TD><TD>ulink0(5)</TD></TR>
  <TR><TD>IP:</TD><TD>()</TD></TR>
  <TR><TD>Max Speed:</TD>
  <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  </TABLE>

 #---------------------------------------------------------------

 Target[10.10.10.1.1]: 10:public@10.10.10.1
 MaxBytes[10.10.10.1.1]: 1250000
 Title[10.10.10.1.1]: LC-Bridge (sample-device): ether0
 PageTop[10.10.10.1.1]: <H1>Traffic Analysis for ether0</H1>
  <TABLE>
  <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  <TR><TD>Interface:</TD><TD>ether0(10)</TD></TR>
  <TR><TD>IP:</TD><TD>sample-device(10.10.10.1)</TD></TR>
  <TR><TD>Max Speed:</TD>
  <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  </TABLE>

 #---------------------------------------------------------------

 Target[10.10.10.1.2]: 24:public@10.10.10.1
 MaxBytes[10.10.10.1.2]: 1250000
 Title[10.10.10.1.2]: LC-Bridge (): ulink0
 PageTop[10.10.10.1.2]: <H1>Traffic Analysis for ulink0</H1>
  <TABLE>
  <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  <TR><TD>Interface:</TD><TD>ulink0(24)</TD></TR>
  <TR><TD>IP:</TD><TD>()</TD></TR>
  <TR><TD>Max Speed:</TD>
  <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  </TABLE>

 #---------------------------------------------------------------

 # Router CPU load %
 Target[cpu.1]:1.3.6.1.4.1.9.2.1.58.0&1.3.6.1.4.1.9.2.1.58.0:public@10.10.10.1
 RouterUptime[cpu.1]: public@10.10.10.1
 MaxBytes[cpu.1]: 100
 Title[cpu.1]: CPU LOAD
 PageTop[cpu.1]: <H1>CPU Load %</H1>
 Unscaled[cpu.1]: ymwd
 ShortLegend[cpu.1]: %
 XSize[cpu.1]: 380
 YSize[cpu.1]: 100
 YLegend[cpu.1]: CPU Utilization
 Legend1[cpu.1]: CPU Utilization in % (Load)
 Legend2[cpu.1]: CPU Utilization in % (Load)
 Legend3[cpu.1]:
 Legend4[cpu.1]:
 LegendI[cpu.1]:
 LegendO[cpu.1]: &nbsp;Usage
 Options[cpu.1]: gauge

This is a nice example of how to monitor any SNMP device if you know what OID you want to use. Once again, for an explanation of the more advance features of mrtg, please see the rest of the documentation.