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 setup 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 (ie. 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 drives familiarise yourself with the use and limitations of UNC paths and install the service as a local or domain user. Refer to this article on configuring FireDaemon to use mapped drives or UNC paths.
You can also use FireDaemon usion to manage your MRTG services via a web browser.
Download and install the latest version of the following software:
- MRTG 2.17.4. Unzip 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:
On Sophos UTM you might configure it as follows:Code: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 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
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):
You then need to edit the configuration file that you just generated (in this case dlink.cfg). Use Notepad or your favourite text editor and insert the the following lines at the start (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):Code:cd \program files\mrtg-2.17.4\bin perl cfgmaker [email protected] --output dlink.cfg
Change WorkDir to where you want MRTG to generate it's 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. (ie. C:\PROGRA~1\APACHE~1\APACHE2\HTDOCS\MRTG). A quick way of determining the 8.3 naming of your path is (at a command prompt) to change directory to your WorkDir then type the following:Code:RunAsDaemon: yes Interval: 5 WorkDir: C:\PROGRA~1\APACHE~1\APACHE2\HTDOCS\MRTGAlso, 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):Code:for %I in (.) do echo %~sI
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.Code:perl mrtg --logging=mrtg.log dlink.cfg
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. Start the FireDaemon Service Manager from the Start/Programs menu or desktop icon.
At the top of this HOWTO, you can download the service definition file which makes initial setup of your FireDaemon service easier.
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 (adjust your paths and configuration file names to suite) - you can use the TAB or SHIFT+TAB keys to move between fields:
Now click on the Settings tab and uncheck Interact with Desktop:
Then install the service by clicking on the Install 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 (look for firedaemon.exe and perl.exe) and that the MRTG statistics are being updated (point your browser at 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 (eg. 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. Simply 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 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.
- The FireDaemon Process was Started
- The Service Failed To Shutdown Correctly ...
- SubProcess Monitoring Failed ...
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.
If your MRTG configuration is good then you should see something like this in the log file:
- 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:@main::DEBUG=qw();
- Modify this line to read the following:Code:@main::DEBUG=qw(base);
- 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
Search throught this file looking for any errors. For example:Code: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
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:Code: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.
- 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.