mrtg-nt-guide.txt
上传用户:shbosideng
上传日期:2013-05-04
资源大小:1555k
文件大小:17k
源码类别:

SNMP编程

开发平台:

C/C++

  1. MRTG-NT-GUIDE(1)               mrtg              MRTG-NT-GUIDE(1)
  2. NNAAMMEE
  3.        mrtg-nt-guide - The Windows Guide to MRTG 2.13.2
  4. SSYYNNOOPPSSIISS
  5.        Installing MRTG on a Windows box is not quite as "click
  6.        and point" as some might want it to be. But then again, it
  7.        is not all that difficult if you follow the instructions
  8.        below.
  9. PPRREERREEQQUUIISSIITTEESS
  10.        To get MRTG to work on Windows you need the following:
  11.        +o   A current copy of Perl.  For Example ActivePerl from
  12.            http://www.activestate.com/Products/Download/Down-
  13.            load.plex?id=ActivePerl
  14.        +o   The latest version of MRTG from http://peo-
  15.            ple.ee.ethz.ch/~oetiker/webtools/mrtg/pub Look for
  16.            mrtg-2.13.2.zip or better. The archive also contains a
  17.            precompiled copy of rateup.exe for Win32.
  18. IINNSSTTAALLLLIINNGG
  19.        I suggest you do the following from the machine that will
  20.        be running MRTG, which, in this case, is also a web
  21.        server. All examples are for doing things to a LOCAL
  22.        machine.
  23.        First
  24.            Unzip MRTG to C:mrtg-2.13.2 on the Windows machine of
  25.            your choice.
  26.        Next
  27.            Install Perl on the same Windows machine. You might
  28.            want to make sure that the Perl binary directory is
  29.            listed in your system path.
  30.             C:Perlbin;%SystemRoot%system32;%SystemRoot%;...
  31.            You can manually check this by going to [Control
  32.            Panel]->[System]->[Environment]
  33.        To see if everything is installed properly you can open a
  34.        Command Shell and go into _c_:__m_r_t_g_-_2_._1_3_._2__b_i_n. Type:
  35.         perl mrtg
  36.        This should give you a friendly error message complaining
  37.        about the missing MRTG configuration file. Now, you have
  38.        successfully installed MRTG and Perl.
  39. CCOONNFFIIGGUURRIINNGG MMRRTTGG
  40.        Now it is time to create a configuration for MRTG. But
  41.        before we begin you need to know a few things. Take an
  42.        opportunity to gather the following information:
  43.        +o   The IP address or hostname and the SNMP port number,
  44.            (if non standard), of the device you want to monitor.
  45.        +o   If you want to monitor something other than bytes in
  46.            and out, you must also know the SNMPOID of what you
  47.            want to monitor.
  48.        +o   Finally you need to know the read-only SNMP community
  49.            string for your device. If you don't know it, try ppuubb--
  50.            lliicc, that is the default.
  51.        For the rest of this document we will be using device
  52.        1100..1100..1100..11 ( a CISCO Catalyst 5000) with Community string
  53.        ppuubblliicc. We are interested in monitoring traffic, and the
  54.        CPU load. Let's begin.
  55.        The first thing we do in setting up MRTG is making a
  56.        default config file.  Get to a cmd prompt and change to
  57.        the _c_:__m_r_t_g_-_2_._1_3_._2__b_i_n directory. Type the following com-
  58.        mand:
  59.         perl cfgmaker public@10.10.10.1 --global "WorkDir: c:wwwmrtg" --output mrtg.cfg
  60.        This creates an initial MRTG config file for you. Note
  61.        that in this file all interfaces of your router will be
  62.        stored by number. Unfortunately, these numbers are likely
  63.        to change whenever you reconfigure your router. In order
  64.        to work around this you can get _c_f_g_m_a_k_e_r to produce a con-
  65.        figuration which is based on Ip numbers, or even Interface
  66.        Descriptions. Check cfgmaker
  67.        If you get an error message complaining about nnoo ssuucchh nnaammee
  68.        or nnoo rreessppoonnssee, your community name is probably wrong.
  69.        Now, let's take a look at the mrtg.cfg file that was cre-
  70.        ated.
  71.        In Perl, a "#" is a comment, synonymous with "REM" in DOS.
  72.        Add the following to the top of the mrtg.cfg file:
  73.         WorkDir: D:InetPubwwwrootMRTG
  74.        This is where the web pages are created, usually a web
  75.        root.
  76.         ######################################################################
  77.         # Description: LCP SUWGB
  78.         # Contact: Administrator
  79.         # System Name: LC-Bridge
  80.         # Location: Here
  81.         #.....................................................................
  82.        TargetDevice's IP Address:Interface Number:Community:IP
  83.        Address
  84.         Target[10.10.10.1.1]: 1:public@10.10.10.1
  85.        This is the interface speed (Default is 10 megabits; for
  86.        100Mbit devices use 12500000 and so on...)
  87.         MaxBytes[10.10.10.1.1]: 1250000
  88.         Title[10.10.10.1.1]: LC-Bridge (sample.device): ether0
  89.        This section determines how the web page headers will look
  90.         PageTop[10.10.10.1.1]: <H1>Traffic Analysis for ether0</H1>
  91.          <TABLE>
  92.          <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  93.          <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  94.          <TR><TD>Interface:</TD><TD>ether0(1)</TD></TR>
  95.          <TR><TD>IP:</TD><TD>sample.device(10.10.10.1)</TD></TR>
  96.          <TR><TD>Max Speed:</TD>
  97.          <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  98.          </TABLE>
  99.          Target[10.10.10.1.2]: 2:public@10.10.10.1
  100.          MaxBytes[10.10.10.1.2]: 1250000
  101.          Title[10.10.10.1.2]: LC-Bridge (): ulink0
  102.          PageTop[10.10.10.1.2]: <H1>Traffic Analysis for ulink0</H1>
  103.           <TABLE>
  104.           <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  105.           <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  106.           <TR><TD>Interface:</TD><TD>ulink0(2)</TD></TR>
  107.           <TR><TD>IP:</TD><TD>()</TD></TR>
  108.           <TR><TD>Max Speed:</TD>
  109.           <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  110.           </TABLE>
  111.          #---------------------------------------------------------------
  112.        And that's a very basic MRTG config file. You can run this
  113.        and see your results by going into the _c_:__m_r_t_g_-_2_._1_3_._2__b_i_n
  114.        directory and typing:
  115.         perl mrtg mrtg.cfg
  116.        It is normal to get errors for the first two times you run
  117.        this command. The errors will alert you about the fact
  118.        that there have not been any log files in existence
  119.        before.
  120.        If you take a look at those web pages they are not very
  121.        exciting (yet). You need to have the MRTG files run every
  122.        five minutes to produce the desired results.  Just run it
  123.        again after a few minutes. You should now be able to see
  124.        the first lines in your graphs.
  125. MMAAKKEE MMRRTTGG RRUUNN AALLLL TTHHEE TTIIMMEE
  126.        Starting MRTG by hand every time you want to run it is not
  127.        going to make you happy I guess.
  128.        There is a special option you can set in the MRTG configu-
  129.        ration file so so that MRTG will not terminate after it
  130.        was started. Instead it will wait for 5 minutes and then
  131.        run again.
  132.        Add the option
  133.         RunAsDaemon: yes
  134.        to your mrtg.cfg file and start it with:
  135.         start /Dc:mrtg-2.13.2bin wperl mrtg --logging=eventlog mrtg.cfg
  136.        If you use wwppeerrll instead of ppeerrll, no console window will
  137.        show. MRTG is now running in the background. If it runs
  138.        into problems it will tell you so over the EventLog. To
  139.        stop MRTG, open the Task Manager and terminate the
  140.        wwppeerrll..eexxee process. If mrtg has anything to tell you these
  141.        messages can be found in the event log.
  142.        If you put a shortcut with
  143.         Target:    wperl mrtg --logging=eventlog mrtg.cfg
  144.         Start in:  c:mrtg-2.13.2bin
  145.        into your start-up folder, MRTG will now start whenever
  146.        you login to your NT box.
  147.        If you do not want to log into your box just to start
  148.        MRTG. Have a look at http://www.firedae-
  149.        mon.com/mrtg-howto.html which describes a free tool to
  150.        start any program as a Service. The pages gives specific
  151.        instructions for MRTG users.
  152. HHOOWW TTOO SSEETTUUPP MMRRTTGG AASS AA WWIINNDDOOWWSS SSEERRVVIICCEE
  153.        AAddddiittiioonnaall PPrreerreeqquuiissiitteess
  154.        +o   MRTG must be installed and fully configured on the
  155.            target system.  In the following exercise the assump-
  156.            tion is that MRTG is installed under c:mrtg and all
  157.            the sample files use this location.
  158.        +o   Microsoft Tools SSRRVVAANNYY..eexxee (Applications as Services
  159.            Utility) and IINNSSTTSSRRVV..eexxee (Service Installer) - Those
  160.            files can be downloaded from Microsoft as a part of
  161.            Windows 2000 Resource Kit at
  162.            <http://www.microsoft.com/windows2000/tech-
  163.            info/reskit/tools/default.asp>.  They are also avail-
  164.            able from other locations such as <http://www.electra-
  165.            soft.com/srvany/srvany.htm>,
  166.            <http://www.iopus.com/guides/srvany.htm>, etc.
  167.            Detailed instructions on how to use this package are
  168.            available at <http://sup-
  169.            port.microsoft.com/kb/q137890/>.  In order to follow
  170.            the steps in this HOW-TO you MMUUSSTT obtain both executa-
  171.            bles.
  172.        +o   You must have administrative rights on the target sys-
  173.            tem.
  174.        PPrreeppaarraattiioonn
  175.        Please complete the following steps before starting the
  176.        installation:
  177.        +o   Copy ssrrvvaannyy..eexxee and iinnssttssrrvv..eexxee to c:mrtgbin (your
  178.            MRTG bin directory).
  179.        +o   Create a file called mmrrttgg..rreegg anywhere on your system
  180.            and paste the following content into it:
  181.             Windows Registry Editor Version 5.00
  182.             [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesMRTGParameters]
  183.             "Application"="c:\perl\bin\wperl.exe"
  184.             "AppParameters"="c:\mrtg\bin\mrtg --logging=eventlog c:\mrtg\bin\mrtg.cfg"
  185.             "AppDirectory"="c:\mrtg\bin\"
  186.        SSeerrvviiccee IInnssttaallllaattiioonn
  187.        Once again, assuming that MRTG is already fully installed
  188.        and configured on the target system under c:mrtg the
  189.        following steps are necessary to setup MRTG as a service.
  190.        Using the command prompt go into the temporary directory
  191.        where you unzipped the package.  When there type the fol-
  192.        lowing command to create a service named "MRTG" in the
  193.        Windows Services management console:
  194.         instsrv MRTG c:mrtgbinsrvany.exe
  195.        Now you need to create the AApppp** entries required for the
  196.        new service.  You can do this by either right-clicking on
  197.        the mrtg.reg file and selecting 'merge' or by running the
  198.        following command:
  199.         regedit /s mrtg.reg
  200.        After setting up the registry entry it is time to point it
  201.        to your MRTG installation.  If you have installed MRTG
  202.        under _c_:__m_r_t_g_, you can skip this step.  Open your reg-
  203.        istry editor (Start -> Run -> regedt32), and locate the
  204.        [[HHKKEEYY__LLOOCCAALL__MMAACCHHIINNEESSYYSSTTEEMMCCuurrrreennttCCoonnttrroollSSeettSSeerr--
  205.        vviicceessMMRRTTGG]] key.  Make sure that the IImmaaggeePPaatthh variable is
  206.        correctly pointing to ssrrvvaannyy..eexxee located in your MRTG bin
  207.        directory (for example c:mrtgbinsrvany.exe).  Next you
  208.        have to expand the MRTG tree, and go to the
  209.        [[HHKKEEYY__LLOOCCAALL__MMAACCHHIINNEESSYYSSTTEEMMCCuurrrreennttCCoonnttrroollSSeettSSeerr--
  210.        vviicceessMMRRTTGGPPaarraammeetteerrss]] key.  Under Parameters make sure
  211.        that all the  AApppplliiccaattiioonn variables are setup properly.
  212.        At this point you are ready to run the service.  The only
  213.        thing left to do is to start the MRTG service in the Ser-
  214.        vices management console.  After you do this, you should
  215.        see two new processes running on your system: srvany.exe
  216.        and wperl.exe.  Make sure to stop any previously running
  217.        MRTG processes to avoid conflict.
  218.        Note that it is imperative to set the RRuunnAAssDDaaeemmoonn:: yyeess
  219.        option or the service will stop after just one single run!
  220. EEXXAAMMPPLLEE
  221.        Now lets look at a config file to monitor what we wanted
  222.        to on our mythical Cisco Cat 5000 -- utilization on ports
  223.        3, 5, 10, and 24, and the CPU Load, which will show us
  224.        nonstandard mrtg configurations as well as more options..
  225.         WorkDir: D:InetPubwwwrootMRTG
  226.         RunAsDaemon: yes
  227.         ######################################################################
  228.         # Description: LCP SUWGB
  229.         # Contact: Administrator
  230.         # System Name: LC-Bridge
  231.         # Location: Here
  232.         #.....................................................................
  233.         Target[10.10.10.1.1]: 3:public@10.10.10.1
  234.         MaxBytes[10.10.10.1.1]: 1250000
  235.         Title[10.10.10.1.1]: LC-Bridge (sample-device): ether0
  236.         PageTop[10.10.10.1.1]: <H1>Traffic Analysis for ether0</H1>
  237.          <TABLE>
  238.         <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  239.         <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  240.         <TR><TD>Interface:</TD><TD>ether0(3)</TD></TR>
  241.         <TR><TD>IP:</TD><TD>sample-device(10.10.10.1)</TD></TR>
  242.         <TR><TD>Max Speed:</TD>
  243.         <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  244.         </TABLE>
  245.         #---------------------------------------------------------------
  246.         Target[10.10.10.1.2]: 5:public@10.10.10.1
  247.         MaxBytes[10.10.10.1.2]: 1250000
  248.         Title[10.10.10.1.2]: LC-Bridge (): ulink0
  249.         PageTop[10.10.10.1.2]: <H1>Traffic Analysis for ulink0</H1>
  250.          <TABLE>
  251.          <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  252.          <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  253.          <TR><TD>Interface:</TD><TD>ulink0(5)</TD></TR>
  254.          <TR><TD>IP:</TD><TD>()</TD></TR>
  255.          <TR><TD>Max Speed:</TD>
  256.          <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  257.          </TABLE>
  258.         #---------------------------------------------------------------
  259.         Target[10.10.10.1.1]: 10:public@10.10.10.1
  260.         MaxBytes[10.10.10.1.1]: 1250000
  261.         Title[10.10.10.1.1]: LC-Bridge (sample-device): ether0
  262.         PageTop[10.10.10.1.1]: <H1>Traffic Analysis for ether0</H1>
  263.          <TABLE>
  264.          <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  265.          <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  266.          <TR><TD>Interface:</TD><TD>ether0(10)</TD></TR>
  267.          <TR><TD>IP:</TD><TD>sample-device(10.10.10.1)</TD></TR>
  268.          <TR><TD>Max Speed:</TD>
  269.          <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  270.          </TABLE>
  271.         #---------------------------------------------------------------
  272.         Target[10.10.10.1.2]: 24:public@10.10.10.1
  273.         MaxBytes[10.10.10.1.2]: 1250000
  274.         Title[10.10.10.1.2]: LC-Bridge (): ulink0
  275.         PageTop[10.10.10.1.2]: <H1>Traffic Analysis for ulink0</H1>
  276.          <TABLE>
  277.          <TR><TD>System:</TD><TD>LC-Bridge inAndover</TD></TR>
  278.          <TR><TD>Maintainer:</TD><TD>Administrator</TD></TR>
  279.          <TR><TD>Interface:</TD><TD>ulink0(24)</TD></TR>
  280.          <TR><TD>IP:</TD><TD>()</TD></TR>
  281.          <TR><TD>Max Speed:</TD>
  282.          <TD>1250.0 kBytes/s (ethernetCsmacd)</TD></TR>
  283.          </TABLE>
  284.         #---------------------------------------------------------------
  285.         # Router CPU load %
  286.         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
  287.         RouterUptime[cpu.1]: public@10.10.10.1
  288.         MaxBytes[cpu.1]: 100
  289.         Title[cpu.1]: CPU LOAD
  290.         PageTop[cpu.1]: <H1>CPU Load %</H1>
  291.         Unscaled[cpu.1]: ymwd
  292.         ShortLegend[cpu.1]: %
  293.         XSize[cpu.1]: 380
  294.         YSize[cpu.1]: 100
  295.         YLegend[cpu.1]: CPU Utilization
  296.         Legend1[cpu.1]: CPU Utilization in % (Load)
  297.         Legend2[cpu.1]: CPU Utilization in % (Load)
  298.         Legend3[cpu.1]:
  299.         Legend4[cpu.1]:
  300.         LegendI[cpu.1]:
  301.         LegendO[cpu.1]: &nbsp;Usage
  302.         Options[cpu.1]: gauge
  303.        This is a nice example of how to monitor any SNMP device
  304.        if you know what OID you want to use. Once again, for an
  305.        explanation of the more advance features of mrtg, please
  306.        see the rest of the documentation.
  307. AAUUTTHHOORRSS
  308.        Tobi Oetiker <oetiker@ee.ethz.ch>, David S. Divins <ddi-
  309.        vins@moon.jic.com>, Steve Pierce <MRTG@HDL.com>, Artyom
  310.        Adjemov <one.bofh@gmail.com>, Ilja Ivanov <ivanov@bseu.by>
  311.        Karel Fajkus <karel@fajkus.cz>
  312. 2.13.2                      2006-02-03           MRTG-NT-GUIDE(1)