Installation and configuration of MRTG on RHEL 4.
1. Download and install mrtg, use up2date or via rpm.
2. Make sure that the net-snmp-utils package was installed, check by:
# rpm -q net-snmp-utils
If it’s not installed, use up2date or rpm command to install.
3. Check if snmp is running properly, the community string is usually named public, change this according to your preference.
# snmpwalk -v 1 -c public localhost interface
The result is somehow similar to this output:
IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: eth0 IF-MIB::ifDescr.3 = STRING: eth1 IF-MIB::ifPhysAddress.1 = STRING: IF-MIB::ifPhysAddress.2 = STRING: 0:9:5b:2f:9e:d5 IF-MIB::ifPhysAddress.3 = STRING: 0:b0:d0:46:32:7
4. Configure SNMP.
Save the old configuration file.
# cd /etc/snmp
# mv snmpd.conf snmpd.conf.orig
# vi snmpd.conf
Enter the following line in the new configuration file to set the Read Only community string to public.
rocommunity public
Configure Linux to start SNMP services on each reboot with the chkconfig command.
# chkconfig snmpd on
Start SNMP to load the current configuration file.
# service snmpd start
Test whether SNMP can read the system and interface MIBs using the snmpwalk command.
# snmpwalk -v 1 -c public localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.kanati.com.ph 2.6.9-42.0.10.ELsmp #1 SMP Fri Feb 16 17:13:42 EST 2007 x86_64 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 SNMPv2-MIB::sysUpTime.0 = Timeticks: (178700) 0:29:47.00 SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
# snmpwalk -v 1 -c public localhost system
IF-MIB::ifNumber.0 = INTEGER: 8 IF-MIB::ifIndex.1 = INTEGER: 1 IF-MIB::ifIndex.2 = INTEGER: 2 IF-MIB::ifIndex.3 = INTEGER: 3 IF-MIB::ifIndex.4 = INTEGER: 4 IF-MIB::ifIndex.5 = INTEGER: 5 IF-MIB::ifIndex.6 = INTEGER: 6 IF-MIB::ifIndex.7 = INTEGER: 7 IF-MIB::ifIndex.8 = INTEGER: 8 IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: eth0 IF-MIB::ifDescr.3 = STRING: eth1 IF-MIB::ifDescr.4 = STRING: eth2 IF-MIB::ifDescr.5 = STRING: eth3
Now edit snmpd.conf, this is my snmpd.conf
# First, map the community name "public" into a "security name"
# sec.name source community
# com2sec notConfigUser default public
com2sec local localhost public
com2sec network_1 192.168.168.0/24 public
com2sec network_2 10.17.19.0/24 public
com2sec kanati 123.456.78.9 public
####
# Second, map the security name into a group name:
# groupName securityModel securityName
#group notConfigGroup v1 notConfigUser
#group notConfigGroup v2c notConfigUser
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyROGroup1 v1 network_1
group MyROGroup1 v2c network_1
group MyROGroup2 v1 network_2
group MyROGroup2 v2c network_2
group MyROGroup3 v1 kanati
group MyROGroup3 v2c kanati
#### # Third, create a view for us to let the group have rights to: # Make at least snmpwalk -v 1 localhost -c public system fast again. # name incl/excl subtree mask(optional) view all included .1 view systemview included .1.3.6.1.2.1.1 view systemview included .1.3.6.1.2.1.25.1.1 #### # Finally, grant the group read-only access to the systemview view. # group context sec.model sec.level prefix read write notif #access notConfigGroup "" any noauth exact all none none access MyROGroup1 "" any noauth exact all none none access MyROGroup2 "" any noauth exact all none none access MyROGroup3 "" any noauth exact all none none access MyRWGroup "" any noauth exact all all none # -----------------------------------------------------------------------------
5. Configuring MRTG
Use MRTG’s cfgmaker command to create a configuration file named mrtg.cfg for the server using a Read Only community string of public. Place all data files in the directory /var/www/mrtg.
# cfgmaker --output=/etc/mrtg/mrtg.cfg --global "workdir: /var/www/mrtg" -ifref=ip --global 'options[_]: growright,bits' public@localhost
--base: Get Device Info on public@localhost: --base: Vendor Id: --base: Populating confcache --snpo: confcache public@localhost: Descr lo --> 1
....
--base: Walking ifOperStatus --base: Writing /etc/mrtg/mrtg.cfg
Run MRTG using /etc/mrtg/mrtg.cfg as your argument three times. You’ll get an error twice as MRTG tries to move old data files, and naturally, the first time it is run, MRTG has no data files to move.
# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
Use MRTG’s indexmaker command to create a Web index page using your new mrtg.cfg file as a guide. The MRTG Web GUI expects to find the index file in the default MRTG Web directory of /var/www/mrtg/, so the format of the command would be.
# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
MRTG is run every five minutes by default, and the file that governs this is /etc/cron.d/mrtg. For MRTG to work correctly, edit this file, replacing all occurrences of /usr/bin/mrtg with
env LANG=C /usr/bin/mrtg
The RHEL 4 MRTG installation process creates a cron file named /etc/cron.d/mrtg. This file tells the cron daemon to run MRTG using the /etc/mrtg/mrtg.cfg file every five minutes to poll your network devices.
Let’s add other things to monitor such as CPU and Memory. The following is my configuration to query CPU and memoy usage.
#
# File: /etc/mrtg/server-stats.cfg
#
# Configuration file for non bandwidth server statistics
#
#
# Define global options
#
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt,/usr/share/snmp/mibs/TCP-MIB.txt
workdir: /var/www/mrtg/
#
# CPU Monitoring
# (Scaled so that the sum of all three values doesn't exceed 100)
#
Target[server.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCp
uRawNice.0&ssCpuRawNice.0:public@localhost
Title[server.cpu]: Server CPU Load
PageTop[server.cpu]: <H1>CPU Load - System, User and Nice Processes</H1>
MaxBytes[server.cpu]: 100
ShortLegend[server.cpu]: %
YLegend[server.cpu]: CPU Utilization
Legend1[server.cpu]: Current CPU percentage load
LegendI[server.cpu]: Used
LegendO[server.cpu]:
Options[server.cpu]: growright,nopercent
Unscaled[server.cpu]: ymwd
#
# Memory Monitoring (Total Versus Available Memory)
# Target[server.memory]: memAvailReal.0&memTotalReal.0:public@localhost Title[server.memory]: Free Memory PageTop[server.memory]: <H1>Free Memory</H1> MaxBytes[server.memory]: 100000000000 ShortLegend[server.memory]: B YLegend[server.memory]: Bytes LegendI[server.memory]: Free LegendO[server.memory]: Total Legend1[server.memory]: Free memory, not including swap, in bytes Legend2[server.memory]: Total memory Options[server.memory]: gauge,growright,nopercent kMG[server.memory]: k,M,G,T,P,X # # Memory Monitoring (Percentage usage) # Title[server.mempercent]: Percentage Free Memory PageTop[server.mempercent]: <H1>Percentage Free Memory</H1> Target[server.mempercent]: ( memAvailReal.0&memAvailReal.0:public@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:public@ localhost ) options[server.mempercent]: growright,gauge,transparent,nopercent Unscaled[server.mempercent]: ymwd MaxBytes[server.mempercent]: 100 YLegend[server.mempercent]: Memory % ShortLegend[server.mempercent]: Percent LegendI[server.mempercent]: Free LegendO[server.mempercent]: Free Legend1[server.mempercent]: Percentage Free Memory Legend2[server.mempercent]: Percentage Free Memory
Test server-stats.cfg configuration.
# service snmpd restart # env LANG=C /usr/bin/mrtg /etc/mrtg/server-stats.cfg
Create a new MRTG index file to include the server-stats.cfg file
# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg /etc/mrtg/server-stats.cfg
Configuring Crond to use the new MRTG file, To do so, add this line to your /etc/cron.d/mrtg file:
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/server-stats.cfg
Restart the cron daemon.
# service crond restart
That’s all there is to it, were done!