How to install MRTG
MRTG requires the following softwares to be installed in the server.
GD, libpng, perl, zlib, snmp
Please wait while we retrieve data from server .............
The steps for installation and configuration are as follows:
1. Install snmp using the command :
yum -y install net-snmp-utils net-snmp
Start snmp using the command:
/etc/init.d/snmpd start
Verify that snmp is running properly:
netstat -na | grep '0.0.0.0:199'
2. Configure snmp
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
You should get the IP details of the server as output. If not, configure snmp as follows:
vi /etc/snmp/snmpd.conf
Replace the content in there with following:
com2sec local localhost public
com2sec mynetwork 202.0.0.0/8 public
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation "s347"
syscontact Admin
At this point you should be good to go, so lets restart SNMP.
/etc/init.d/snmpd restart
Run this command look for appropriate output as mentioned above.
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
[root@s347 mrtg]# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.202.167.231.112 = INTEGER: 2
IP-MIB::ipAdEntIfIndex.202.167.231.113 = INTEGER: 2
IP-MIB::ipAdEntIfIndex.202.167.231.114 = INTEGER: 2
IP-MIB::ipAdEntIfIndex.202.167.231.115 = INTEGER: 2
IP-MIB::ipAdEntIfIndex.202.167.231.116 = INTEGER: 2
Ok. That is all with SNMP. Now moving on to MRTG installation:
3. Download the mrtg tarball:
cd /usr/src
wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.15.2.tar.gz
tar -xzf mrtg-2.15.2.tar.gz
./configure --prefix=/usr/local/mrtg-2
make
make install
4. Let us set up data directory to store html files:
mkdir /usr/local/apache/htdocs/mrtg
5. Create the mrtg.cfg file using the cfgmaker script in the bin folder
cd /usr/local/mrtg-2/bin
./cfgmaker --global "workdir: /usr/local/apache/htdocs/mrtg" --ifref=ip --output /usr/local/mrtg-2/mrtg1.cfg --global 'options[_]: growright,bits' public@localhost
5. Create the index.html file using the indexmaker script
./indexmaker --output /usr/local/apache/htdocs/mrtg/index.html --title="Bandwidth stats for 202.167.231.112" /usr/local/mrtg-2/mrtg1.cfg
The index.html page will display only the daily graph. To include the weekly and monthly graph, I did the following:
a. Generated weekly and monthly graph pages using the commands:
./indexmaker --output /usr/local/apache/htdocs/mrtg/index-weekly.html --title="Weekly Bandwidth stats for 202.167.231.112" --show=week /usr/local/mrtg-2/mrtg1.cfg
./indexmaker --output /usr/local/apache/htdocs/mrtg/index-monthly.html --title="Monthly Bandwidth stats for 202.167.231.112" --show=month /usr/local/mrtg-2/mrtg1.cfg
b. And pasted only the relevant html portions from these html files to index.html.
6. Lastly, setup the cronjob for periodic update of the graph.
*/5 * * * * /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/mrtg1.cfg --logging /var/log/mrtg.log