[HOWTO] Install MRTG SNMP Monitoring Inside Jail
Posted: 02 Nov 2013 13:22
[HOWTO] Install MRTG SNMP Monitoring Inside Jail
Tested on:
NAS4Free 9.1.0.1 - Sandstorm (rev 804 & 847)
Platform x64-Embedded on 512MB USB Flash Stick on HP Microserver N40L (AMD64)
Works on Apache 2.2 and 2.4 without additional configuration
This guide will detail how to install MRTG in a jail to monitor SNMP-enabled devices. This will require no previous experience or knowledge of MRTG, SNMP or Apache and will consist of as minimal configuration as possible to get you started. There will always be other, better ways in doing most of this however the methods outlined here have worked for me and should minimise any confusion/frustration.
This guide assumes you have a system running a default installation of N4F with the IP address 192.168.1.250. This server has a new jail called 'mrtg' with an IP address of 192.168.1.251, has fully working Internet access, SSH and a file editor (Nano).
Before I begin, the sources I give credit to are the following:
Alexey123's SNMP + MRTG on Nas4free
Tobi Oetiker's MRTG Homepage
To start with, we need to enable SNMP on the server so we've got something for MRTG to communicate with. To do this, go to Services -> SNMP and enable it as per the following screenshot:
Once complete, SSH into your server and list the jails:
Then enter the jail:
Once in the jail, check the hosts file:
If it doesn't look like the above, enter the following
Next, the necessary packages or ports need to be installed, this guide will outline the procedure for both.
To start with, enter one of the two commands below depending on whether your system is AMD or Intel based:
If you want to use the FreeBSD Ports Collection, install it with the following commands:
If it's already installed, make sure it's up to date:
Next, install the NET-SNMP port:
If you're using packages:
Do the same with Apache 2.2, again using ports:
And with packages:
And finally, install MRTG:
And with packages:
Once these are installed by either method, enter the following:
Next, we need to create the configuration file which MRTG will refer to. This will probe the system specified in the command below and output information on the interfaces which it finds. The 'LoadMIBs' line will enable MRTG to graph CPU, memory etc.
Once complete, the next command will create an index.html file for Apache based on your configuration file:
Then, all you need to do is start Apache if it hasn't been already:
And run the MRTG daemon:
The result will be:
To test it, enter http://192.168.1.251/mrtg into your browser and the index page should show up. Click on the graph to give you more graphs showing usage on a daily/weekly/monthly/yearly basis:
If you want to run Apache and the MRTG daemon automatically each time the jail starts, enter the following:
And that's it! Pretty straightforward and there's still plenty of other things you could graph. If, for example, you want to graph your Active CPU Load in percentage, enter the following at the bottom of the mrtg.cfg file:
Run the indexmaker command again to update index.html and it will start to look like this:
For details on measuring CPU, disk temperature and others, see the post below:
Alexey123's SNMP + MRTG on Nas4free
I hope some of you find this guide useful, any corrections or recommendations are welcome.
Tested on:
NAS4Free 9.1.0.1 - Sandstorm (rev 804 & 847)
Platform x64-Embedded on 512MB USB Flash Stick on HP Microserver N40L (AMD64)
Works on Apache 2.2 and 2.4 without additional configuration
This guide will detail how to install MRTG in a jail to monitor SNMP-enabled devices. This will require no previous experience or knowledge of MRTG, SNMP or Apache and will consist of as minimal configuration as possible to get you started. There will always be other, better ways in doing most of this however the methods outlined here have worked for me and should minimise any confusion/frustration.
This guide assumes you have a system running a default installation of N4F with the IP address 192.168.1.250. This server has a new jail called 'mrtg' with an IP address of 192.168.1.251, has fully working Internet access, SSH and a file editor (Nano).
Before I begin, the sources I give credit to are the following:
Alexey123's SNMP + MRTG on Nas4free
Tobi Oetiker's MRTG Homepage
To start with, we need to enable SNMP on the server so we've got something for MRTG to communicate with. To do this, go to Services -> SNMP and enable it as per the following screenshot:
Once complete, SSH into your server and list the jails:
Code: Select all
Welcome to NAS4Free!
nas4free: ~ # jls
JID IP Address Hostname Path
1 192.168.1.251 mrtg.domain.local /jail/mrtgCode: Select all
nas4free: ~ # jexec 1 csh
root@mrtg:/ #Code: Select all
root@mrtg:/ # cat /etc/hosts
::1 localhost localhost.local
127.0.0.1 localhost localhost.local
192.168.1.250 nas4free nasfree.localCode: Select all
echo '192.168.1.250 nasfree nas4free.local' >> /etc/hostsTo start with, enter one of the two commands below depending on whether your system is AMD or Intel based:
Code: Select all
setenv PACKAGESITE "ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9-current/Latest/"
setenv PACKAGESITE "ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-9-current/Latest/"Code: Select all
portsnap fetch extractCode: Select all
portsnap fetch updateCode: Select all
cd /usr/ports/net-mgmt/net-snmp/
make install cleanCode: Select all
pkg_add -r net-snmpCode: Select all
cd /usr/ports/www/apache22
make install cleanCode: Select all
pkg_add -r apache22Code: Select all
cd /usr/ports/net-mgmt/mrtg/
make install cleanCode: Select all
pkg_add -r mrtgCode: Select all
mkdir /usr/local/www/apache22/data/mrtg
touch /var/log/mrtg.log
chown -R mrtg:mrtg /usr/local/etc/mrtg /usr/local/www/apache22/data/mrtg /var/log/mrtg.logCode: Select all
cfgmaker --global 'WorkDir: /usr/local/www/apache22/data/mrtg' --global 'Options[_]: growright,unknaszero,transparent,bits' --global 'RunAsDaemon: Yes' --global 'LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt' --output /usr/local/etc/mrtg/mrtg.cfg public@192.168.1.250Code: Select all
/usr/local/bin/indexmaker /usr/local/etc/mrtg/mrtg.cfg > /usr/local/www/apache22/data/mrtg/index.htmlCode: Select all
/usr/local/etc/rc.d/apache22 startCode: 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
2013-10-29 21:48:16 -- Started mrtg with config '/usr/local/etc/mrtg/mrtg.cfg'
Daemonizing MRTG ...If you want to run Apache and the MRTG daemon automatically each time the jail starts, enter the following:
Code: Select all
echo 'mrtg_daemon_enable="YES"' >> /etc/rc.conf
echo 'apache22_enable="YES"' >> /etc/rc.confCode: Select all
# CPU Load - NAS4Free
Target[nas4free_cpu]:1.3.6.1.4.1.2021.10.1.3.1&1.3.6.1.4.1.2021.10.1.3.1:public@192.168.1.250:*100
Options[nas4free_cpu]: growright,gauge,noo,nolegend,unknaszero,transparent
RouterUptime[nas4free_cpu]: public@192.168.1.250
Kilo[nas4free_cpu]: 100
MaxBytes[nas4free_cpu]: 100
Unscaled[nas4free_cpu]: dwmy
ShortLegend[nas4free_cpu]: %
YLegend[nas4free_cpu]: Active CPU Load % - NAS4Free
Title[nas4free_cpu]: CPU Load - NAS4Free
PageTop[nas4free_cpu]: <H1>Active CPU Load % - NAS4Free</H1>Run the indexmaker command again to update index.html and it will start to look like this:
For details on measuring CPU, disk temperature and others, see the post below:
Alexey123's SNMP + MRTG on Nas4free
I hope some of you find this guide useful, any corrections or recommendations are welcome.