Installing MRTG and adding additional Data Sources @ Windows
This guide explains how to install MRTG on Windows and monitor different signals like memory and network usage.
MRTG is a software used to monitor different “signals” and display them in nice graphs.
I will use Windows XP as Operating System but it also works on Windows Server 2003.
Download MRTG
I will install mrtg-2.16.2 which can be downloaded here, however you should install the latest version which can be found here.
After downloading it, unpack it to where you want, I will use the following path: C:\mrtg-2.16.2
Install Perl
To run MRTG we need to install Perl first, I would recommend installing ActivePerl which can be found here.
It is pretty simple to install Perl so I won’t cover it, just follow the Setup.
Setting up the SNMP Service
Browse to Control Panel – Add or Remove Programs – Add / Remove Windows Components and then select Management and Monitoring Tools and then click Next.
You will probably be requested to insert the Windows CD to copy the required files.
After installing it, we need to configure it.
Browse to Control Panel – Administrative Tools – Services and then find the Service called SNMP Service, double-click on it and then select the Traps tab.
In the Community name textbox, write public and then click the button Add to list.
Now switch to the Security tab.
Add public to the Accepted community names with the READ ONLY community right.
Then select Accept SNMP packets from these hosts and add 127.0.0.1 to the list.
We have successfully configured SNMP on our Windows machine.
Install MRTG
Now we need access to a Command Prompt. Click Start – Run and then insert cmd and press enter.
In my case I have extracted the MRTG files to the following path: C:\mrtg-2.16.2
cd C:\mrtg-2.16.2\bin
Now we are going to create our MRTG configuration file, the WorkDir is the Path to where you want the files to be written, for example the public folder of your webserver.
perl cfgmaker public@127.0.0.1 –global “WorkDir: c:\xampp\htdocs\mrtg” –output mrtg.cfg
If it doesn’t output anything, then it means it worked.
perl indexmaker –output index.html mrtg.cfg
This will create an html file with the layout. Now copy that index.html file into your WorkDir (in my case c:\xampp\htdocs\mrtg)
copy index.html c:\xampp\htdocs\mrtg
Don’t forget to replace c:\xampp\htdocs\mrtg with your WorkDir!
Run MRTG
We still need a command-prompt. Execute the following commands
cd C:\mrtg-2.16.2\bin
perl mrtg mrtg.cfg
You have now manually triggered mrtg to get the data and draw it into the graphs.
Now we need to make this run automatically as it would be quite annoying if you had to manually run this command every 5 minutes..
Open your mrtg.cfg with a texteditor and add the line RunAsDaemon: yes
Now execute perl mrtg mrtg.cfg once again, MRTG has been started as a daemon, this is quite annoying because the command-prompt has to stay open. You can also create a Windows Service (Click here for additional informations)
Add Memory Usage and other Data sources
First we need to configure the inbuilt Performance Log of Windows. Click on Control Panel – Admistrative Tools – Performance – Performance Logs and Alerts then select Counter Logs, then right-click on the blank window and select New Log Settings.
Now we are going to create a new log, insert a name you want to use and then click OK.
A Counter is only one log, like the memory usage and an object is a collection of informations on memory for example.
Click the button Add Counters or Add Objects.
I am going to add a Counter for this example.
Select Use local Computer counters then select Memory in the Performance Object list then select Avaible MBytes and click Add then Close.
Then select the Log Files tab.
Select Text File(Comma delimited) in the Log file type listbox and then click OK.
Our .csv file is located at C:\PerfLogs\
We are now going to configure a .cfg file in MRTG to parse the .csv file which is created by the Windows Log Tool.
Please note that this script is a little bit buggy and the final results needs some tweaking, such as setting the MaxByte value in the graphs etc. The script has been written by castellan.net
Download the script here. If the link is broken download the mkcfg.vbs script here and the getlog.pl script here (Don’t forget to name the script getlog.pl)
We need a command-prompt. Execute the following commands:
cd C:\mrtg-2.16.2\bin
cscript mkcfg.vbs c:\perflogs\memory.csv memory
This should create 2 files, .html and .cfg.
This is a little bit tricky, the mkcfg.vbs script is a little bit bugy, it repeats the last diagram a couple of times, so open up the memory.cfg with a text-editor and locate the duplicate diagrams. (Should be easy to spot)
After you deleted them, you need to change the WorkDir.
Copy the created .html file into your public mrtg folder and then execute this
perl mrtg memory.cfg
You have created a new graph display for your .csv file! (Don’t forget to update this .cfg file too, refer to Run MRTG for more help)
If the legend isn’t big enough, change MaxBytes in the .cfg file.
You can also include memory.cfg into mrtg.cfg . Add the following line into mrt.cfg
Include: memory.cfg
Indexmaker
Doesn’t it annoy you that you have to visit 2 links to admire your graphs? Indexmaker can bind them together into one page.
perl indexmaker –output index.html mrtg.cfg memory.cfg
This command will bind both mrtg.cfg and memory.cfg into one file, named index.html. Now copy the index.html file into your WorkDir. That’s it. If you want to see detailed informations about a graph, click on it.
Finally
You might want to rename your legends and titles to make the graphs more readable.
I hope this quick guide was somewhat useful, if you have any questions, feel free to post a comment.
Thanks for reading and good luck.
This entry was posted on April 7, 2009 at 8:46 pm and is filed under MRTG, Operating Systems, Projects, Windows with tags 2003, cfgmaker, configure, graph, indexmaker, install, memory, mkcfg.vbs, MRTG, processor, server, usage, Windows, xp. You can follow any responses to this entry through the RSS 2.0 feed You can leave a response, or trackback from your own site.



May 25, 2009 at 7:25 am
Очень хороший пост! Спасибо за проделанную работу!
August 11, 2009 at 10:30 pm
I have been working with MRTG for years and have moved to BB4 a few years ago. However, I am trying to look back and monitor multiple location without being so invasive on bandwidth. Have you bined WMI/Cscript yet with your MRTG cfg files? Very cool stuff. I will be managing a project to monitor 100 stores and 12 servers in the next month have any cool suggestions? I have had a whole lot of success with MRTG in the past but have been out of the picture for a while.
Thanks,
Rob