How to Install MRTG system monitoring with SNMP Support

Contributions by: created based on contribution by several people
Created/Updated: 11-10-2006  
Versions supported: 5.5, 5.6 and 6.0 and NOT SME7

 


Since this is one of the howto's used very often I have decided to make a install script for it. Basically the install script does exactly what is outlined below except for the fact that I had to make some choices for you here and there. The script will install MRTG monitoring of your LAN and WAN connections, Root Disk usage and CPU utilization. If you have Spamassassin and/or Clam Antivirus installed it will also add statistics for that. If you want to do it all manually then proceed to Manual MRTG Installation

First Create an ibay called "mrtg"

Information bay name mrtg
Description MRTG system monitor
Group Admin
User access Write=group, Read=everyone
Public access As you like it
Execution of dynamic content disabled

First download the script and simply run it!!

[root@e-smith ]# wget http://sme.swerts-knudsen.dk/downloads/MRTG/mrtg_install.sh

[root@e-smith ]# sh mrtg_install.sh

 

NOTE: You should expect that to see some "Rateup WARNING: in the end of the script.

 

Now wait 5 minutes and then try to look at

 

http://server.domain.com/mrtg/

An example of MRTG can be seen here


Manual MRTG installation

First install the two SNMP packages

[root@e-smith ]# rpm -Uvh http://sme.swerts-knudsen.dk/downloads/MRTG/ucd-snmp-4.2.5-7.73.0.i386.rpm

[root@e-smith ]# rpm -Uvh http://sme.swerts-knudsen.dk/downloads/MRTG/ucd-snmp-utils-4.2.5-7.73.0.i386.rpm

 

Then install the MRTG package

[root@e-smith ]# rpm -Uvh http://sme.swerts-knudsen.dk/downloads/MRTG/mrtg-2.9.17-3.i386.rpm

You then need to change the hosts.allow file to allow access to the snmp deamon

Issue the following commands at console:

[root@e-smith ]# mkdir -p /etc/e-smith/templates-custom/etc/hosts.allow
[root@e-smith ]# echo "snmpd: 127.0.0.1, 192.168.212.0/255.255.255.0" > /etc/e-smith/templates-custom/etc/hosts.allow/snmpd
[root@e-smith ]# /sbin/e-smith/expand-template /etc/hosts.allow

You can replace the "127.0.0.1, 192.168.212.0/255.255.255.0" with "ALL" if you allow SNMP requests from the anywhere.

Then we need to make sure that the SNMP deamon is allowed to prope the right values. This is done by adding or modifying the following entries in the snmpd.conf file.

[root@e-smith ]# cd /etc/snmp

[root@e-smith ]# pico snmpd.conf

# First, map the community name (COMMUNITY) into a security name 

# (local and mynetwork, depending on where the request is coming 

# from):

#                 sec.name     source         community 

com2sec     local             localhost       public

 

# Second, map the security names into group names: 

#                             sec.model         sec.name 

group MyROGroup     v1                    local 

group MyROGroup     v2c                   local 

group MyROGroup     usm                 local

 

# Third, create a view for us to let the groups have rights to: 

#                  incl/excl     subtree     mask 

view     all     included     .1             80

 

# Finally, grant the group access to the 1 view with different # write permissions: 

#                         context     sec.model sec.level match     read  write     notif 

access MyROGroup ""            any          noauth    exact      all     none     none

 

You now want to make sure that the SNMP deamon is restarted when/if the server is rebooted:

[root@e-smith ]# cd /etc/rc.d/rc7.d

[root@e-smith ]# ln -s /etc/rc.d/init.d/snmpd S95snmpd

[root@e-smith ]# /sbin/e-smith/config set snmpd service InitscriptOrder 95 status enabled

Now make sure to start the SNMP deamon to have the new setting take effect

[root@e-smith ]# service snmpd start

Now you are ready to do the actual MRTG installation:

1) Then create an ibay called "mrtg" from the server manager

Information bay name: mrtg
Description: MRTG System Monitor
Group: everyone
User access: Write=group, Read=everyone
Public access: (As you like it)
Execution of dynamic content: disabled

2) Create the MRTG script

[root@e-smith ]# cd /root

[root@e-smith ]# pico create-mrtg

Now paste the following text into PICO and save the files by pressing CTRL-X, Y, to save. Make sure not to have line-breaks in the middle of the different commands.

#!/bin/bash
#This script will create a folder inside the ibay "mrtg" which is named by the first variable. It will create a cfg file inside the /etc/mrtg folder. 

#It will also add a line to the script "/etc/mrtg/all-ip" so that #crontab will run this script which in turn will run mrtg for each device. 

#The second variable is the IP address of each device to be monitored..This script is best run when "all" the workstations connected to 

#it are powered up because "cfgmaker" ignores inactive ports when it is run.
#       EX:
#                                                              Var1     Var2
#                                                                 |         | 
#           [root@e-smith /root]# create-mrtg 10001 10.0.0.1

# Create a "workdir" for this device using the first variable
mkdir -p /home/e-smith/files/ibays/mrtg/html/$1

#create the cfg file for this Ip address using the first variable (assumes community string is "public")
perl /usr/bin/cfgmaker public@$2 --global "workdir: /home/e-smith/files/ibays/mrtg/html/$1" --output /etc/mrtg/$1.cfg

#Create an index.html file for this folder using the first variable
perl /usr/bin/indexmaker /etc/mrtg/$1.cfg > /home/e-smith/files/ibays/mrtg/html/$1/index.html

#create an entry in script "all-ip" to run mrtg for each device. 
echo "/usr/bin/mrtg /etc/mrtg/$1.cfg;" >> /etc/mrtg/all-ip 

#Uncommenting the line below will create a "master" index.htm inside the ibay/html directory for all devices.
#Note that this line will create a text file called index.html. This should be edited for correct html syntax.

#echo "<br><a href=$1/index.html> Traffic on ports of Device $1 </a>" >> /home/e-smith/files/ibays/mrtg/html/index.html

3) make the script executable

[root@e-smith ]# chmod 755 create-mrtg

4) Now run create-mrtg

                                                   var1        var 2

                                                    |            |

[root@e-smith ]# ./create-mrtg     server     10.0.0.1

5) You now need to make sure that the update is run with regular intervals (every 5mins) so we insert it in the Crontab scheduler

[root@e-smith ]# chmod 755 /etc/mrtg/all-ip

[root@e-smith ]# mkdir -p /etc/e-smith/templates-custom/etc/crontab/

[root@e-smith ]# echo "0-59/5 * * * * root /etc/mrtg/all-ip" > /etc/e-smith/templates-custom/etc/crontab/mrtg

[root@e-smith ]# /sbin/e-smith/expand-template /etc/crontab

 

6) Now wait 5 minutes and then try to look at

 

http://server.domain.com/mrtg/server

If you also want to monitor your disk as well as CPU usage you can do the following:

First you need to add a disk entry in your snmp.conf file. Here is an example of an snmpd.conf file from my system.

[root@e-smith ]# cd /etc/snmp

[root@e-smith ]# pico snmp.conf

find the Disk Check section or add the parameters:

###############################################################################
# disk checks
#
# The agent can check the amount of available disk space, and make
# sure it is above a set limit. 
# disk PATH [MIN=DEFDISKMINIMUMSPACE]
#
# PATH: mount path to the disk in question.
# MIN: Disks with space below this value will have the Mib's errorFlag set.
# Default value = DEFDISKMINIMUMSPACE.
# Check the / partition and make sure it contains at least 10 megs.

disk / 10000
disk /boot 10000
###############################################################################

Make sure to specify existing mounts. Press CTRL-X, Y , to save when complete. Your mounts can bee found by executing the mount command:

You then need to restart the snmp deamon to enable the new parameters.

[root@e-smith ]# service snmpd restart

You now need to create MRTG config files for your CPU and Disk. 

[root@e-smith ]# cd /etc/mrtg

[root@e-smith ]# pico system.cfg

Now inserts the following text and press CTRL-X, Y, to save.

workdir: /home/e-smith/files/ibays/mrtg/html/system

Interval: 5

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

 

Target[kontor.cpu]: ssCpuRawUser.0&ssCpuRawIdle.0:public@localhost

RouterUptime[kontor.cpu]: public@localhost

MaxBytes[kontor.cpu]: 100

Title[kontor.cpu]: CPU LOAD

PageTop[kontor.cpu]: <H1>User CPU Load %</H1>

Unscaled[kontor.cpu]: ymwd

ShortLegend[kontor.cpu]: %

YLegend[kontor.cpu]: CPU Utilization

Legend1[kontor.cpu]: User CPU in % (Load)

Legend2[kontor.cpu]: Idle CPU in % (Load)

#Legend3[kontor.cpu]:

#Legend4[kontor.cpu]:

LegendI[kontor.cpu]: User

LegendO[kontor.cpu]: Idle

Options[kontor.cpu]: growright,nopercent

 

Target[kontor.cpusum]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost

RouterUptime[kontor.cpusum]: public@localhost

MaxBytes[kontor.cpusum]: 100

Title[kontor.cpusum]: CPU LOAD

PageTop[kontor.cpusum]: <H1>Active CPU Load %</H1>

Unscaled[kontor.cpusum]: ymwd

ShortLegend[kontor.cpusum]: %

YLegend[kontor.cpusum]: CPU Utilization

Legend1[kontor.cpusum]: Active CPU in % (Load)

Legend2[kontor.cpusum]:

Legend3[kontor.cpusum]:

Legend4[kontor.cpusum]:

LegendI[kontor.cpusum]: Active

LegendO[kontor.cpusum]:

Options[kontor.cpusum]: growright,nopercent

 

Target[kontor.root]:dskPercent.1&dskPercent.2:public@localhost

RouterUptime[kontor.root]: public@localhost

MaxBytes[kontor.root]: 100

Title[kontor.root]: Disk Usage on Server

PageTop[kontor.root]: <H1>Root and Boot Disk Usage %</H1>

Unscaled[kontor.root]: ymwd

ShortLegend[kontor.root]: %

YLegend[kontor.root]: Disk Utilization

Legend1[kontor.root]: Root disk

Legend2[kontor.root]: Boot disk:

Legend3[kontor.root]: 

Legend4[kontor.root]:

LegendI[kontor.root]: Root disk:

LegendO[kontor.root]: Boot disk:

Options[kontor.root]: growright,gauge,nopercent

Now we just need to make sure this new MRTG config file is run every 5 minutes. 

[root@e-smith ]# pico all-ip

Insert the following line in the bottom and press CTRL-X, Y, to save:

/usr/bin/mrtg /etc/mrtg/system.cfg;

6) Now wait 5 minutes and then try to look at

 

http://server.domain.com/mrtg/system

An example of MRTG can be seen here