This is the old XigmaNAS forum in read only mode,
it will taken offline by the end of march 2021!



I like to aks Users and Admins to rewrite/take over important post from here into the new fresh main forum!
Its not possible for us to export from here and import it to the main forum!

[HOWTO] Install MRTG SNMP Monitoring Inside Jail

Jails with XigmaNAS
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
Snunn1
Starter
Starter
Posts: 35
Joined: 05 Sep 2013 21:55
Status: Offline

[HOWTO] Install MRTG SNMP Monitoring Inside Jail

Post by Snunn1 »

[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:
N4F - SNMP.jpg
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/mrtg
Then enter the jail:

Code: Select all

nas4free: ~ # jexec 1 csh
root@mrtg:/ #
Once in the jail, check the hosts file:

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.local
If it doesn't look like the above, enter the following

Code: Select all

echo '192.168.1.250 nasfree nas4free.local' >> /etc/hosts
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:

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/"
If you want to use the FreeBSD Ports Collection, install it with the following commands:

Code: Select all

portsnap fetch extract
If it's already installed, make sure it's up to date:

Code: Select all

portsnap fetch update
Next, install the NET-SNMP port:

Code: Select all

cd /usr/ports/net-mgmt/net-snmp/
make install clean
If you're using packages:

Code: Select all

pkg_add -r net-snmp
Do the same with Apache 2.2, again using ports:

Code: Select all

cd /usr/ports/www/apache22
make install clean
And with packages:

Code: Select all

pkg_add -r apache22
And finally, install MRTG:

Code: Select all

cd /usr/ports/net-mgmt/mrtg/
make install clean
And with packages:

Code: Select all

pkg_add -r mrtg
Once these are installed by either method, enter the following:

Code: 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.log
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.

Code: 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.250
Once complete, the next command will create an index.html file for Apache based on your configuration file:

Code: Select all

/usr/local/bin/indexmaker /usr/local/etc/mrtg/mrtg.cfg > /usr/local/www/apache22/data/mrtg/index.html
Then, all you need to do is start Apache if it hasn't been already:

Code: Select all

/usr/local/etc/rc.d/apache22 start
And run the MRTG daemon:

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.cfg
The result will be:

Code: Select all

2013-10-29 21:48:16 -- Started mrtg with config '/usr/local/etc/mrtg/mrtg.cfg'
Daemonizing MRTG ...
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:
N4F - LAN.jpg
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.conf
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:

Code: 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:
N4F - CPU and LAN.jpg
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.
You do not have the required permissions to view the files attached to this post.
NAS4Free 10.2.0.2.2545 P14 Embedded on 1GB USB Key
HP N40L Microserver - 8GB ECC RAM, 3x Seagate 500GB RAIDZ1, 1x Seagate 500GB UFS & 1x 200GB SATA
Extensions: RRDGraphs

Post Reply

Return to “Jails”