webcp.hostinghacks.net/slackware | mrtg

home   ·.   download   ·.   install   ·.   faq   ·.   forums   ·.   contribute   ·.   change log   ·.   toolbox
SYNOPSIS

MRTG provides a live visual representation of network and server performance statistics by generating graphical images. See http://fatpenguinhosting.com/mrtg-stats/ for a sample of the output.

PREREQUISITES: MRTG depends on gd + libpng as installed @ webcp.hostinghacks.net/slackware/libraries/ + zlib

last updated: June 2005

INSTALLATION
The installation commands can be run from a Putty window in a "cut-and-paste" style layout or copied to a script. Notes on Putty best practices can be found here.

MRTG : a tool to monitor the traffic load on network-links ; http://people.ee.ethz.ch/~oetiker/webtools/mrtg/.

cd /usr/src
wget http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/mrtg-2.11.1.tar.gz
# wget http://hostinghacks.net/dist/mrtg-2.11.1.tar.gz

tar -zxf mrtg-2.11.1.tar.gz
cd /usr/src/mrtg-2.11.1

./configure --prefix=/usr
make
make install

mkdir -p /etc/mrtg

create a web accessible directory to store mrtg traffic graphs:

mkdir -p /home/fatpenguinhosting.com/www/web/mrtg-stats/

Create the MRTG configuration file:

cfgmaker --global 'WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/' \
--output /etc/mrtg/traffic.cfg moonshine199@192.168.0.10

edit the new /etc/mrtg.cfg file
do a search and replace
this will make for a better URL address (to access statistics):

vim /etc/mrtg/traffic.cfg
:g/192.168.0.10_2/s//traffic/g

Run mrtg at least 3 times and ignore error messages:


/usr/bin/mrtg /etc/mrtg/traffic.cfg
/usr/bin/mrtg /etc/mrtg/traffic.cfg
/usr/bin/mrtg /etc/mrtg/traffic.cfg

Access the statistics with a web browser: http://fatpenguinhosting.com/mrtg-stats/traffic.html. The numbers will be disturbingly low until MRTG has run for a while.

SYSTEM PERFORMANCE STATS:

cpu usage:

cat > /etc/mrtg/cpu.cfg << "EOF"
### Global Defaults
Options[_]: gauge, absolute, nopercent, withzeroes
WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
LoadMIBs: /etc/snmp/mibs/UCD-SNMP-MIB.txt,/etc/snmp/mibs/TCP-MIB.txt

# CPU Monitoring
# (Scaled so that the sum of all three values doesn't exceed 100)
# make sure no line breaks on the Target[] line:

Target[cpu]:ssCpuRawUser.0&ssCpuRawUser.0:moonshine199@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:moonshine199@localhost + ssCpuRawNice.0&ssCpuRawNice.0:moonshine199@localhost
Title[cpu]: Server CPU Load
PageTop[cpu]: <H1>CPU Load - System, User and Nice Processes</H1>
MaxBytes[cpu]: 100
ShortLegend[cpu]: %
YLegend[cpu]: CPU Utilization
Legend1[cpu]: Current CPU percentage load
LegendI[cpu]: Used
LegendO[cpu]:
Options[cpu]: growright,nopercent
Unscaled[cpu]: ymwd
EOF

/usr/bin/mrtg /etc/mrtg/cpu.cfg

memory graphs

cat > /etc/mrtg/mem.cfg << "EOF"

WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
LoadMIBs: /etc/snmp/mibs/UCD-SNMP-MIB.txt,/etc/snmp/mibs/TCP-MIB.txt

Target[mem]: memAvailReal.0&memTotalReal.0:moonshine199@localhost
Title[mem]: Free Memory
PageTop[mem]: <H1>Free Memory</H1>
MaxBytes[mem]: 100000000000
ShortLegend[mem]: B
YLegend[mem]: Bytes
LegendI[mem]: Free
LegendO[mem]: Total
Legend1[mem]: Free memory, not including swap, in bytes
Legend2[mem]: Total memory
Options[mem]: gauge,growright,nopercent
kMG[mem]: k,M,G,T,P,X
EOF

/usr/bin/mrtg /etc/mrtg/mem.cfg

new tcp connections:

cat > /etc/mrtg/tcp.new.cfg << "EOF"
### Global Defaults
WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
LoadMIBs: /etc/snmp/mibs/UCD-SNMP-MIB.txt,/etc/snmp/mibs/TCP-MIB.txt

Target[tcp.new]: tcpPassiveOpens.0&tcpActiveOpens.0:moonshine199@localhost
Title[tcp.new]: New TCP Connections
PageTop[tcp.new]: <H1>New TCP Connections</H1>
MaxBytes[tcp.new]: 10000000000
ShortLegend[tcp.new]: c/s
YLegend[tcp.new]: Conns / Min
LegendI[tcp.new]: In
LegendO[tcp.new]: Out
Legend1[tcp.new]: New inbound connections
Legend2[tcp.new]: New outbound connections
Options[tcp.new]: growright,nopercent,perminute
EOF

/usr/bin/mrtg /etc/mrtg/tcp.new.cfg

tcp established connections:

cat > /etc/mrtg/tcp.established.cfg << "EOF"

WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
LoadMIBs: /etc/snmp/mibs/UCD-SNMP-MIB.txt,/etc/snmp/mibs/TCP-MIB.txt

Target[tcp.established]: tcpCurrEstab.0&tcpCurrEstab.0:moonshine199@localhost
Title[tcp.established]: Currently Established TCP Connections
PageTop[tcp.established]: <H1>Established TCP Connections</H1>
MaxBytes[tcp.established]: 10000000000
ShortLegend[tcp.established]:
YLegend[tcp.established]: Connections
LegendI[tcp.established]: In
LegendO[tcp.established]:
Legend1[tcp.established]: Established connections
Legend2[tcp.established]:
Options[tcp.established]: growright,nopercent,gauge
EOF

 /usr/bin/mrtg /etc/mrtg/tcp.established.cfg

modwatch - first make sure mod_watch is active:

 
/usr/sbin/mod_watch.pl -f ifRequests,ifActive http://fatpenguinhosting.com/watch-info
cat > /etc/mrtg/web.cfg << "EOF" 
### Global Defaults
Options[_]: perhour
WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
LoadMIBs: /etc/snmp/mibs/UCD-SNMP-MIB.txt,/etc/snmp/mibs/TCP-MIB.txt

Target[web]: `/usr/sbin/mod_watch.pl -f ifRequests,ifActive http://fatpenguinhosting.com/watch-info`
MaxBytes[web]: 1250000
YLegend[web]: Hits per Hour
ShortLegend[web]: H/h
Legend1[web]: Request (raw hits) received per Hour
Legend2[web]: Documents sent per Hour
Legend3[web]: Maximal 5 Minute Incoming Request Traffic
Legend4[web]: Maximal 5 Minute Outgoing Document Traffic
LegendI[web]: Hits
LegendO[web]: Docs
Title[web]: HTTP Request & Document Traffic
PageTop[web]: <H1>HTTP Request & Document Traffic</H1>
 <TABLE>
   <TR><TD>System:</TD>     <TD>serv1.fatpenguinhosting.com</TD></TR>
   <TR><TD>Description:</TD><TD>Apache 2.x</TD></TR>
 </TABLE>
EOF

 /usr/bin/mrtg /etc/mrtg/web.cfg

Run MRTG every five minutes in a cron job:

cat > /var/spool/cron/crontabs/root << "EOF"
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 4 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
#
*/5 * * * * /usr/bin/mrtg /etc/mrtg/traffic.cfg  1> /dev/null
*/5 * * * * /usr/bin/mrtg /etc/mrtg/cpu.cfg  1> /dev/null
*/5 * * * * /usr/bin/mrtg /etc/mrtg/mem.cfg 1> /dev/null
*/5 * * * * /usr/bin/mrtg /etc/mrtg/web.cfg 1> /dev/null
*/5 * * * * /usr/bin/mrtg /etc/mrtg/tcp.new.cfg 1> /dev/null
*/5 * * * * /usr/bin/mrtg /etc/mrtg/tcp.established.cfg 1> /dev/null
EOF

chmod 600 /var/spool/cron/crontabs/root

killall crond
/usr/sbin/crond -l10
Traffic Statistics on the XP/2000 Desktop:

On a windows XP box you can have MRTG graphs sitting on your desktop and updating continually. Just right click on the graph and choose "set as desktop item". once you have done that click on the graph on you desktop in the top left corner of the bar and choose "properties" > "schedule' > then set it to update itself once a day.

You can now keep an eye on your server traffic effortlessly. With a little more configuring you can even set it to have 1 hour or 20 minute updates for some real time stats.

This works with any image that is updated on the internet on a regular basis. You can have fun with this technique with a webcam. Try a Construction Webcam and watch a building or freeway being built.

NOTES:

alternate method to graph cpu and memory usage:

$ snmpget -v 1 -c private localhost .1.3.6.1.4.1.2021.10.1.5.1
UCD-SNMP-MIB::laLoadInt.1 = INTEGER: 0

$ snmpget -v 1 -c private localhost .1.3.6.1.4.1.2021.10.1.5.2
UCD-SNMP-MIB::laLoadInt.2 = INTEGER: 0

$ snmpget -v 1 -c private localhost .1.3.6.1.4.1.2021.10.1.5.3
UCD-SNMP-MIB::laLoadInt.3 = INTEGER: 0
cat > /etc/mrtg/cpu.cfg << "EOF"
### Global Defaults
Options[_]: gauge, absolute, nopercent, withzeroes
WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
#Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1
#private@localhost:
MaxBytes[cpu]:    100
YLegend[cpu]:     Load Average(%)
LegendI[cpu]:     1min
LegendO[cpu]:     5min
ShortLegend[cpu]: %
Unscaled[cpu]:    dwmy
Title[cpu]:       CPU Analysis - hacks -
PageTop[cpu]:     <H1>CPU Analysis - hacks -</H1>
 <TABLE>
   <TR><TD>System:</TD>     <TD>serv1.fatpenguinhosting.com</TD></TR>
   <TR><TD>Description:</TD><TD>Pentium 1400MHz</TD></TR>
 </TABLE>
EOF

 /usr/bin/mrtg /etc/mrtg/cpu.cfg
$ snmpget -v 1 -c private localhost .1.3.6.1.4.1.2021.4.3.0
UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 1024120

$ snmpget -v 1 -c private localhost .1.3.6.1.4.1.2021.4.4.0
UCD-SNMP-MIB::memAvailSwap.0 = INTEGER: 1012492

$ snmpget -v 1 -c private localhost .1.3.6.1.4.1.2021.4.5.0
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 223156

$ snmpget -v 1 -c private localhost .1.3.6.1.4.1.2021.4.6.0
UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 7992

cat > /etc/mrtg/mem.cfg << "EOF" 
### Global Defaults
Options[_]: gauge, absolute
WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
Target[mem]: .1.3.6.1.4.1.2021.4.6.0
#Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:
#private@localhost:
MaxBytes1[mem]:   223156
MaxBytes2[mem]:   1024120
Unscaled[mem]:    dwmy
kilo[mem]:        1024
kMG[mem]:         k,M,G,T,P
YLegend[mem]:     Memory Free(MB)
ShortLegend[mem]: Bytes
LegendI[mem]:     Real
LegendO[mem]:     Swap
Title[mem]:       Memory Free -
PageTop[mem]:     <H1>Memory Free -</H1>
# <TABLE>
#   <TR><TD>System:</TD>     <TD>serv1.fatpenguinhosting.com</TD></TR>
#   <TR><TD>Description:</TD><TD>Real:256Byte , SWAP:512MB</TD></TR>
#</TABLE>
EOF

 /usr/bin/mrtg /etc/mrtg/mem.cfg
 

Disk Usage Monitoring >> this needs work before it will be functional !?

cat > /etc/mrtg/disk.cfg << "EOF"
### Global Defaults
WorkDir: /home/fatpenguinhosting.com/www/web/mrtg-stats/
LoadMIBs: /etc/snmp/mibs/UCD-SNMP-MIB.txt,/etc/snmp/mibs/TCP-MIB.txt


#
# Disk Usage Monitoring
#
Target[server.disk]: dskPercent.1&dskPercent.2:moonshine199@localhost
Title[server.disk]: Disk Partition Usage
PageTop[server.disk]: <H1>Disk Partition Usage /home and /var</H1>
MaxBytes[server.disk]: 100
ShortLegend[server.disk]: %
YLegend[server.disk]: Utilization
LegendI[server.disk]: /home
LegendO[server.disk]: /var
Options[server.disk]: gauge,growright,nopercent
Unscaled[server.disk]: ymwd
EOF

 /usr/bin/mrtg /etc/mrtg/disk.cfg

root@serv1:~#  /usr/bin/mrtg /etc/mrtg/disk.cfg
SNMP Error:
Received SNMP response with error code
  error status: noSuchName
  index 2 (OID: 1.3.6.1.4.1.2021.9.1.9.2)
SNMPv1_Session (remote host: "localhost" [127.0.0.1].161)
                  community: "moonshine199"
                 request ID: 1984522412
                PDU bufsize: 8000 bytes
                    timeout: 2s
                    retries: 5
                    backoff: 1)
 at /usr/bin/../lib/mrtg2/SNMP_util.pm line 490
SNMPGET Problem for dskPercent.1 dskPercent.2 sysUptime sysName on moonshine199@localhost::::::v4only
 at /usr/bin/mrtg line 1849
ERROR: Target[server.disk][_IN_] ' $target->[0]{$mode} ' did not eval into defined data
ERROR: Target[server.disk][_OUT_] ' $target->[0]{$mode} ' did not eval into defined data
Rateup WARNING: /usr/bin/rateup Can't remove server.disk.old updating log file
REFERENCES:

Join the mrtg mailing list: http://people.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg-forum.html

Search the list archives via google: yourkeywordhere "mrtg@list.ee.ethz.ch" site:www.ee.ethz.ch

http://www.mathematik.uni-kassel.de/docu/mrtg-2.5.2/mrtg-conf.html - a detailed list of configuration file options

http://apt-get.dk/mrts/
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/

Some examples of the wide range of the possible uses of MRTG: http://people.ee.ethz.ch/~oetiker/webtools/mrtg/users.html

Powered By Fat Penguin Hosting   |   Disclaimer