Multi Router Traffic Grapher (MRTG) is an excellent tool to monitor the traffic load on network-links (amongst other things). It achieves this by examining the various OID's of SNMP enabled devices that you specify to produce a range of graphs. It is written in Perl. Here's an example screenshot:
It's relatively easy to set up MRTG to run as a service under Windows. However, before you begin we recommend that your read ALL the documentation shipped with MRTG and available from the MRTG master web site: MRTG - Tobi Oetiker's MRTG - The Multi Router Traffic Grapher.
Detailed documentation on configuring MRTG under Windows can be found here: MRTG - The MRTG 2.17.4 Windows Installation Guide
We strongly recommend that your get MRTG going manually before attempting to run it as a service (i.e. make it the last step in your installation process). The example that we give below is very simple and concentrates on configuring MRTG and FireDaemon correctly.
Attempting to run MRTG off or generating output to network drives is not recommended. MRTG and FireDaemon should be installed locally. If you really have to use a network drive, familiarise yourself with the use and limitations of UNC paths and install the service as a local or domain user. Read more on configuring FireDaemon to use mapped drives or UNC paths.
You can also use FireDaemon Fusion to manage your MRTG services via a web browser.
SoftwareDownload and install the latest version of the following software:
- MRTG 2.17.4. Unzip the .zip file and install into C:\Program Files\mrtg-2.17.4
- ActiveState ActivePerl 5.8.8 (look for the Download Now button). Install into C:\Perl. If you download the 64-bit version of ActivePerl it will be installed into C:\Perl64
- FireDaemon Pro. Install into C:\Program Files\FireDaemon. If you install the 32-bit version of FireDaemon Pro on a 64-bit version of Windows it will be installed into C:\Program Files (x86)\FireDaemon.
Your SNMP configuration will be dependent on the device or software you are setting up. For example, on a Brocade ethernet switch you might configure SNMP as follows:
aaa authentication snmp-server default local snmp-server community public ro snmp-server community private rw snmp-server contact James Bourne snmp-server location Cambridge, UK interface ethernet 1/1 port-name External Interface interface ethernet 1/2 port-name Internal Interface
On Sophos UTM you might configure it as follows:
On a DLink DSL-G604T you might configure it as follows:
You are going to need to setup a web server in order to serve the HTML pages MRTG generates. LightTPD, IIS or Apache all work fine under Windows. You will need to create a directory under your web server that MRTG can write to. For example: C:\Program Files\Apache2\htdocs\mrtg or C:\lighttpd\htdocs\mrtg.
MRTG Configuration File
The next step is to create an MRTG configuration file. Your community strings and IPs are specific to your installation. Do this as follows at a command prompt (Start/Run/cmd):
cd \program files\mrtg-2.17.4\bin perl cfgmaker firstname.lastname@example.org --output dlink.cfg
You then need to edit the configuration file that you just generated (in this case dlink.cfg). Ensure you elevate your text editor to run as Administrator in order to be able to save into C:\Program Files\mrtg--2.17.4\bin. Then use your favourite text editor and insert the the following lines at the start.
RunAsDaemon: yes Interval: 5 WorkDir: C:\PROGRA~1\APACHE~1\APACHE2\HTDOCS\MRTG
Change WorkDir to where you want MRTG to generate its HTML files and PNG graphs. MRTG won't accept a WorkDir with spaces in the name. Either use a WorkDir path with no spaces or use the 8.3 abbreviation. (i.e. C:\PROGRA~1\APACHE~1\APACHE2\HTDOCS\MRTG). A quick way of determining the 8.3 naming of your path is to change directory to your WorkDir at a command prompt, then type the following:
for %I in (.) do echo %~sI
Note that setting your Interval to less than 5 minutes will cause an error. Now run MRTG manually to test your configuration as follows. You might have to kill off MRTG via the Task Manager since it has been daemonised:
perl mrtg --logging=mrtg.log dlink.cfg
Check your WorkDir and confirm that the various HTML and PNG files have been generated and that there are no errors in the log file (mrtg.log). Alternately, you can log to the Windows EventLog by substituting "eventlog" for "mrtg.log" above.
FireDaemon Pro Configuration
Once you are satisfied that your MRTG configuration is doing what you want and generating the appropriate graphs, you need to set it up as a service with FireDaemon Pro. Start the FireDaemon Service Manager from the Start/Programs menu or desktop icon.
Click on the Create A New Service Definition button in the Toolbar or press Ctrl+N. Fill out the panel as per the screen shot below. Make sure to adjust your paths and configuration file names to suit your installation.
- Executable: The path to your perl.exe file. For the purposes of this HOWTO, the path is C:\Perl\bin\perl.exe.
- Working Directory: The path to your MRTG bin directory. For the purposes of this HOWTO, the path is C:\Program Files\mrtg-2.17.4\bin.
- Parameters: mrtg --logging=mrtg.log dlink.cfg
Now click on the Settings tab and uncheck Interact with Desktop:
Then install the service by clicking on the OK button. The service should install without errors and start automatically. Check that the service has been started correctly by examining the process list in the Task Manager by looking for firedaemon.exe and perl.exe. Also check that the MRTG statistics are being updated by pointing your browser to http://localhost/mrtg/. You can also check the Windows event log for FireDaemon events and errors.
Running Multiple MRTG Instances
You can run multiple instances of MRTG on the same machine. Just ensure that you create a service with a differing name (e.g. mrtg1, mrtg2 etc.). It is also advisable to configure each MRTG instance independently of each other (ie. differing configuration files, target HTML directories and so forth).
Exporting FireDaemon Service Configurations
FireDaemon service configurations can be exported to XML. Drag and drop the service definition from the main FireDaemon GUI onto your desktop. Alternately, you can bulk import/export via batch script.
OK, so you have installed MRTG, tested the installation to the n-th degree and you now notice that your Application Event Log is filling up with a three FireDaemon error messages:
- The FireDaemon Process was Started
- The Service Failed To Shutdown Correctly ...
- SubProcess Monitoring Failed ...
The error messages are generated by FireDaemon's Service Monitoring Facility (SMF). In a nutshell: MRTG is dying because of a misconfiguration. So how do you debug your configuration? There are several approaches but you are going to need: a text editor that handles Unix end of line characters (eg. VIM), your trusty Perl reference manual and some patience.
MRTG from versions 2.9.17 onwards include a command line switch: --logging, which allows all debugging and other output to be written to a file.
The most common error is that the MRTG configuration file is broken. For example, spaces in front of configuration directives (as listed above) will break your MRTG installation. If you are writing your output to a directory located on a network drive then you are going to have to setup your service to run as a local or domain user in order to access shares via mapped drive letter or UNC path.
Below is one approach to track down MRTG errors.
- Ensure that your MRTG Service has been stopped via FireDaemon Service Manager, Services Applet or command line: net stop mrtg
- Ensure that you have read _ALL_ the MRTG documentation
- Ensure that you have followed this guide to letter!
- Open a console window (command prompt - Start/Run/cmd.exe)
- Change directory to your MRTG bin folder (eg. C:\Program Files\mrtg-2.17.4\bin)
- Edit the file 'mrtg' with your text editor (eg. gvim mrtg)
- Look for the following line: Code:
- Modify this line to read the following: Code:
- Save and quit out of your text editor
- Now attempt to run MRTG damonised manually: perl mrtg -logging=mrtg.log astaro.cfg
- If you want even more debugging: perl -w mrtg --logging=mrtg.log dlink.cfg (or -W)
- Any configuration or processing errors will be easy to spot
- Review the contents of your log file if you specified the --logging option
If your MRTG configuration is good then you should see something like this in the log file:
2014-05-22 03:31:54 -- Started mrtg with config 'dlink.cfg' 2014-05-22 03:31:54 -- --base: Creating Lockfiles dlink.cfg_l,dlink.cfg_l_932 2014-05-22 03:31:54 -- --base: Reading Config File: dlink.cfg 2014-05-22 03:31:54 -- --base: Reading Interface Config cache 2014-05-22 03:31:54 -- --base: Checking Config File 2014-05-22 03:31:54 -- --base: Loading default Locale 2014-05-22 03:31:54 -- --base: Starting main Loop 2014-05-22 03:31:54 -- --base: Populate Target object by polling SNMP and external Datasources 2014-05-22 03:31:54 -- --base: Act on Router/Target 10.1.1.1_2 2014-05-22 03:31:54 -- --base: Get Current values: in:0, out:453298, up:8 days, 13:03:55, name:DSL-G604T, time:1148232714 2014-05-22 03:31:54 -- --base: Create Graphics 2014-05-22 03:31:54 -- --base: Check for Thresholds 2014-05-22 03:31:54 -- --base: Check for Write HTML Pages 2014-05-22 03:31:54 -- --base: Act on Router/Target 10.1.1.1_3 2014-05-22 03:31:54 -- --base: Get Current values: in:52374150, out:19040990, up:8 days, 13:03:55, name:DSL-G604T, time:1148232714 2014-05-22 03:31:54 -- --base: Create Graphics 2014-05-22 03:31:54 -- --base: Check for Thresholds 2014-05-22 03:31:54 -- --base: Check for Write HTML Pages 2014-05-22 03:31:54 -- --base: Act on Router/Target 10.1.1.1_5 2014-05-22 03:31:54 -- --base: Get Current values: in:0, out:0, up:8 days, 13:03:55, name:DSL-G604T, time:1148232714 2014-05-22 03:31:54 -- --base: Create Graphics 2014-05-22 03:31:54 -- --base: Check for Thresholds 2014-05-22 03:31:54 -- --base: Check for Write HTML Pages 2014-05-22 03:31:54 -- --base: Act on Router/Target 10.1.1.1_6 2014-05-22 03:31:54 -- --base: Get Current values: in:15392606, out:52639324, up:8 days, 13:03:55, name:DSL-G604T, time:1148232714 2014-05-22 03:31:54 -- --base: Create Graphics 2014-05-22 03:31:54 -- --base: Check for Thresholds 2014-05-22 03:31:54 -- --base: Check for Write HTML Pages
Search throught this file looking for any errors. For example:
2014-05-22 03:34:34 -- Started mrtg with config 'dlink.cfg' 2014-05-22 03:34:34 -- --base: Creating Lockfiles dlink.cfg_l,dlink.cfg_l_1164 2014-05-22 03:34:34 -- --base: Reading Config File: dlink.cfg 2014-05-22 03:34:34 -- --base: Reading Interface Config cache 2014-05-22 03:34:34 -- --base: Checking Config File 2014-05-22 03:34:34 -- ERROR: CFG Error in "Interval": should be at least 5 Minutes (unless you use rrdtool) at c:/program files/mrtg-2.17.4/bin\..\lib\mrtg2/MRTG_lib.pm line 737. 2014-05-22 03:34:40 -- Started mrtg with config 'dlink.cfg' 2014-05-22 03:34:40 -- --base: Creating Lockfiles dlink.cfg_l,dlink.cfg_l_1844 2014-05-22 03:34:40 -- --base: Reading Config File: dlink.cfg 2014-05-22 03:34:40 -- --base: Reading Interface Config cache 2014-05-22 03:34:40 -- --base: Checking Config File 2014-05-22 03:34:40 -- ERROR: CFG Error in "Interval": should be at least 5 Minutes (unless you use rrdtool) at c:/program files/mrtg-2.17.4/bin\..\lib\mrtg2/MRTG_lib.pm line 737.
Now attempt to restart your MRTG Service: net start mrtg. If you are still seeing error messages in your Application Event Log then review your debug log files. Also it is highly likely that the arguments you stipulated when you installed MRTG as a service with FireDaemon are erroneous. We suggest you do the following:
- Remove your existing service via the FireDaemon Service Manager or command line: "%FIREDAEMON%" --uninstall mrtg
- Reinstall the service with FireDaemon checking that the arguments you are passing to it are correct.
For example, if your MRTG configuration file is myrouter.cfg then when you specify your Application Options type: mrtg myrouter.cfg. DON'T TYPE: mrtg dlink.cfg because THIS WILL NOT WORK because you do not have a configuration file called dlink.cfg.
Issues When Running Multiple FireDaemon / MRTG Services
You may run into Application Initialization errors when running extremely large numbers of non-interactive FireDaemon/MRTG services (30-40+).
Whilst at first this might seem like a problem with FireDaemon it is actually because the default size of the non-interactive window station desktop heap is too small. In order to fix this we need to increase the size of the desktop heap for each desktop that is associated with a "non interactive" window station.
Read this article for more information on how to increase the size of the desktop heap.
In summary, MRTG is a comprehensive yet complicated product. Breaking it via misconfiguration is extremely easy. We urge you to read the MRTG documentation carefully and fully test your configuration of MRTG in daemonised and non-daemonised modes employing the debugging tips listed above before attempting to convert it to a service with FireDaemon.