[HOWTO] Use RRDTool with MRTG
Posted: 14 Sep 2014 21:35
[HOWTO] Use RRDTool with MRTG
Tested on:
NAS4Free 9.2.0.1 - Shigawire (rev 943 & 972)
Platform x64-Embedded on 1GB USB Flash Stick on HP Microserver N40L (AMD64)
Continuing on from my previous guide, [HOWTO] Install MRTG SNMP Monitoring Inside Jail, this guide will focus on using MRTG with RRDTool. For this, we will be using the mrtg-rrd.cgi file included in this guide which will be accessible through Apache. This mrtg-rrd.cgi is one I have modified slightly to use the default MRTG configuration file and to provide nicer graphs. The original version can be found at the MRTG-RRD homepage HERE, please click HERE for example graphs using the original version.
This guide assumes you have a system with a jail called 'mrtg' with an IP address of 192.168.1.251, fully working Internet access, SSH and a file editor (Nano). This jail will also have a working installation of MRTG and Apache 2.x as per my previous guide. Please note that this will be using Apache 2.4 which has a few config differences in comparison to Apache 2.2.
Before I begin, the sources I give credit to are the following:
Tobi Oetiker's MRTG Homepage
Jan "Yenya" Kasprzak's MRTG-RRD Homepage
First, we need to enter the jail:
Next, if you're using the FreeBSD Ports Collection, you'll want to make sure it's up to date:
Then, we need to install the RRDTool port:
If you're using packages as opposed to ports, use this:
This will give MRTG the means to use RRDTool and will convert its logfiles to RRD database files.
We now need to edit the MRTG config to tell it to use RRDTool:
To do this, add the following to the existing 'Global Defaults' section:
Once complete, we need to stop any existing MRTG processes and restart so it picks up the config changes:
This should be the response you see:
MRTG should now create and write to new RRD files, so check the timestamps to confirm this is happening:
Now, we need to change the ownership of the image and HTML files so Apache can write to them:
Next, we need to configure Apache to work with CGI files so we can use mrtg-rrd.cgi. For this, you'll need to edit Apache's main configuration file - httpd.conf:
Search for the following line:
And unhash it so it looks like this:
Next, make sure the following line is mentioned just before the <Directory> section so Apache knows where to look and how to work with CGI files:
We now need to set tell Apache who can access it and what it's for so ensure this section is below the ScriptAlias line:
If you're using Apache 2.2, you'll need this instead:
Once complete, you'll need to save and exit the file. Next step is to download, decompress and move the mrtg-rrd.cgi to the cgi-bin directory and set its permissions and ownership:
Please note that if your existing mrtg.cfg file is anywhere but the default, you'll need to edit the mrtg-rrd.cgi so it knows where to look.
The final step is to restart Apache so it picks up the config changes and uses mrtg-rrd.cgi:
By now, you should be able to enter http://192.168.1.251/cgi-bin/mrtg-rrd.cgi into your browser and the index page should show up with your new RRD-drawn graphs! Click on the graph to give you daily/weekly/monthly/yearly usage.
If Apache displays an error such as 403 Forbidden, check the Apache error logs for clues, this may be due to permissions:
If your graphs aren't updating, you'll need to check that the image files are owned by Apache:
And the RRD files are owned by MRTG:
And that's it! If it's up and working, you'll now have much prettier, slicker graphs! If you want to create your own RRD graphs with multiple lines and remove MRTG altogether, Haroon Rafique's RRD.CGI would be worth investigating. This will require some understanding of how RRDTool works so is worth doing if you're willing to learn.
I hope some of you find this guide useful, any corrections or recommendations are welcome.
Tested on:
NAS4Free 9.2.0.1 - Shigawire (rev 943 & 972)
Platform x64-Embedded on 1GB USB Flash Stick on HP Microserver N40L (AMD64)
Continuing on from my previous guide, [HOWTO] Install MRTG SNMP Monitoring Inside Jail, this guide will focus on using MRTG with RRDTool. For this, we will be using the mrtg-rrd.cgi file included in this guide which will be accessible through Apache. This mrtg-rrd.cgi is one I have modified slightly to use the default MRTG configuration file and to provide nicer graphs. The original version can be found at the MRTG-RRD homepage HERE, please click HERE for example graphs using the original version.
This guide assumes you have a system with a jail called 'mrtg' with an IP address of 192.168.1.251, fully working Internet access, SSH and a file editor (Nano). This jail will also have a working installation of MRTG and Apache 2.x as per my previous guide. Please note that this will be using Apache 2.4 which has a few config differences in comparison to Apache 2.2.
Before I begin, the sources I give credit to are the following:
Tobi Oetiker's MRTG Homepage
Jan "Yenya" Kasprzak's MRTG-RRD Homepage
First, we need to enter the jail:
Code: Select all
nas4free: ~ # jexec 1 csh
root@mrtg:/ #Code: Select all
portsnap fetch updateCode: Select all
cd /usr/ports/databases/rrdtool/
make install cleanCode: Select all
pkg install databases/rrdtoolWe now need to edit the MRTG config to tell it to use RRDTool:
Code: Select all
nano /usr/local/etc/mrtg/mrtg.cfgCode: Select all
LogFormat: rrdtool
WorkDir: /usr/local/www/apache24/data/mrtg
PathAdd: /usr/local/bin/
LibAdd: /usr/local/bin/
IconDir: /mrtg
RunAsDaemon: Yes
Code: Select all
env LANG=C /usr/local/bin/mrtg --logging /var/log/mrtg.log --user mrtg --group mrtg --daemon /usr/local/etc/mrtg/mrtg.cfgCode: Select all
2014-09-01 21:48:16 -- Started mrtg with config '/usr/local/etc/mrtg/mrtg.cfg'
Daemonizing MRTG ...Code: Select all
ls -ltr /usr/local/www/apache24/data/mrtg/*.rrdCode: Select all
chown www:www *.png; chown www:www *.html; chown mrtg:mrtg *.rrdCode: Select all
nano /usr/local/etc/apache24/httpd.confCode: Select all
#LoadModule cgi_module libexec/apache24/mod_cgi.soCode: Select all
LoadModule cgi_module libexec/apache24/mod_cgi.soCode: Select all
ScriptAlias /cgi-bin/ "/usr/local/www/apache24/cgi-bin/"Code: Select all
<Directory "/usr/local/www/apache24/cgi-bin">
AllowOverride None
Options +ExecCGI
Require all granted
</Directory>Code: Select all
<Directory "/usr/local/www/apache22/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>Code: Select all
tar -zxvf mrtg-rrd.tgz
mv mrtg-rrd.cgi /usr/local/www/apache24/cgi-bin
chown www:www mrtg-rrd.cgi; chmod 755 mrtg-rrd.cgiThe final step is to restart Apache so it picks up the config changes and uses mrtg-rrd.cgi:
Code: Select all
/usr/local/etc/rc.d/apache24 restartIf Apache displays an error such as 403 Forbidden, check the Apache error logs for clues, this may be due to permissions:
Code: Select all
less /var/log/httpd-error.logCode: Select all
ls -ltr /usr/local/www/apache24/data/mrtg/*.imgCode: Select all
ls -ltr /usr/local/www/apache24/data/mrtg/*.rrdI hope some of you find this guide useful, any corrections or recommendations are welcome.