MRTG, a tool to monitor your network

From NAS-Central Buffalo - The Linkstation Wiki
Revision as of 08:02, 1 August 2006 by Viper (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article Based on work by falseneutral. Originally by Knatterman. at

Network traffic analysis with MRTG on Linkstation

This article describes the setup of mrtg It is assumed you do this on a debianized linkstation.

Ensure you have mrtg and snmpd (If you do not have them:)

apt-get install snmpd  
apt-get install mrtg   

Setup snmpd

Move the original /etc/snmp/snmpd.conf to a save place, e.g.

mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.original 

Create a new snmpd.conf with the following content:

(This example creates a community named "test" for the SNMP Daemon)

com2sec                         local     localhost        test       
group MyROGroup v1              local                                 
group MyROGroup v2c             local                                 
group MyROGroup usm             local                                 
view all    included  .1        80                                    
access MyROGroup ""      any    noauth    exact  all    none   none   
disk    /usr
disk    /mnt

Restart the snmpd daemon

/etc/init.d/snmpd restart 

Setup mrtg

cfgmaker --global 'WorkDir: /var/www/apache2-default/mrtg/' --global 'Options[_]: bits,growright' --output /root/mrtg.cfg test@localhost 

This will setup mrtg. The html files will be created in the directory /var/www/apache2-default/mrtg/. The config file for mrtg will be stored in the directory /root and is named as mrtg.conf

To add more statistics edit /root/mrtg.cfg and add the following lines. This will add CPU, memory and disk statistics:

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

# cpu utilization 
Target[server.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:test@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:test@localhost + ssCpuRawNice.0&ssCpuRawNice.0:test@localhost
Title[server.cpu]: Server CPU Load
PageTop[server.cpu]: CPU Load - System, User and Nice Processes
MaxBytes[server.cpu]: 100
ShortLegend[server.cpu]: %
YLegend[server.cpu]: CPU Utilization
Legend1[server.cpu]: Current CPU percentage load
LegendI[server.cpu]: Used
Options[server.cpu]: growright,nopercent
Unscaled[server.cpu]: ymwd

# free memory
Target[server.memory]: memAvailReal.0&memTotalReal.0:test@localhost
Title[server.memory]: Free Memory
PageTop[server.memory]: Free Memory
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
# free memory in percentage
Title[server.mempercent]: Percentage Free Memory
PageTop[server.mempercent]: Percentage Free Memory
Target[server.mempercent]: ( memAvailReal.0&memAvailReal.0:test@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:test@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

# disk statistics (/usr and /mnt as configured in /etc/snmp/snmpd.conf
Target[server.disk]: dskPercent.1&dskPercent.2:test@localhost
Title[server.disk]: Disk Partition Usage
PageTop[server.disk]: Disk Partition Usage /usr and /mnt
MaxBytes[server.disk]: 100
ShortLegend[server.disk]: %
YLegend[server.disk]: Utilization
LegendI[server.disk]: /usr
LegendO[server.disk]: /mnt
Options[server.disk]: gauge,growright,nopercent
Unscaled[server.disk]: ymwd

Start mrtg

/usr/bin/mrtg /root/mrtg.cfg 

After the first & second start you will get messages like

Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_2
Rateup WARNING: /usr/bin/rateup The backup log file for localhost_2 was invalid as well
Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file
Rateup WARNING: /usr/bin/rateup Can't rename localhost_2.log to localhost_2.old updating log file

The messages will disappear after the 3rd start

Automize the start

crontab -e 

insert the line

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/mrtg /root/mrtg.cfg 

This will update your page every 5 Minutes

The results

You can see your networktraffic if you have a look on /var/www/apache2-default/mrtg/localhost_2.html (or similar). The other statistics will be written to "server.cpu.html", "server.memory.html" and "server.disk.html".

More details

man mrtg        
man smnpd       
man snmpd.conf  
man crontab     

HTH Knatterman

updated by Viper (added CPU, memory and disk utilization)

Originally by Knatterman and edited by falseneutral from