The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing graphical images which provide a LIVE visual representation of this traffic.
# Get the rpm
wget http://www.dedicated-resources.com/files/m…cpanel.i386.rpm
# Installing the app
rpm -Uvh mrtg-2.9.17-1cpanel.i386.rpm
# Moving libpng
cd /usr/lib
mv libpng.so.2 libpng.so.2.OLD
# Creating the symlink
ln -s libpng.so.3 libpng.so.2
# Edit language at and specify only “en_US”
pico /etc/sysconfig/i18n
# Restarting MRTG
service mrtg restart
# Configurating MRTG to allow only our local IP to see the reports at http://IP/mrtg
vi /usr/local/apache/conf/httpd.conf
#Search for the line (CTRL+W):
# It should look like this:
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
# Restarting httpd
service httpd restart
# Let’s put MRTG to start with the system
chkconfig –level 0123456 mrtg on
If you have problems with Exim after MRTG is restarted, you don’t have to worry about that because that mean that you don’t have no mail, and MRTG takes that as an error, but if you don’t want to see those error messages, you can do this:
# Edit file:
vi /etc/mrtg/check-email
delete all lines and past the given lines
#! /bin/sh
echo “Working.”
LOGFILE=/var/log/exim_mainlog
DAY=`date “+19%y-%m-%d”`
QUE=`find /var/spool/exim/input -name ‘*-H’ | wc -l | sed -e “s/ //g”`
DAYDEL=`/bin/grep -c ” [=-]> ” $LOGFILE`
DAYREC=`/bin/grep -c ” <= ” $LOGFILE`
cat << EOM
======================================================================
E-mail status information for `hostname`
Current Date/Time is: `date “+%A, %D %R %Z”`
Number of messages currently in the queue: $QUE
Number of messages received so far today: $DAYREC
Number of messages delivered so far today: $DAYDEL
EOM
######################
#edit /etc/mrtg/email-count1
delete all lines and past the given lines
#! /bin/sh
INFILE=/etc/mrtg/aux/$1.infile
OUTFILE=/etc/mrtg/aux/$1.outfile
/etc/mrtg/check-email > /tmp/$1
NEWIN=`grep “Number of messages received so far today:” /tmp/$1 | awk ‘{print $8}’`
NEWOUT=`grep “Number of messages delivered so far today:” /tmp/$1 | awk ‘{print $8}’`
if [ -f $INFILE ]; then
OLDIN=`cat $INFILE`
else
OLDIN=0
fi
if [ -f $OUTFILE ]; then
OLDOUT=`cat $OUTFILE`
else
OLDOUT=0
fi
if [ “$NEWIN” -lt “$OLDIN” ] ; then
IN=$NEWIN
OUT=$NEWOUT
else
IN=`expr $NEWIN – $OLDIN`
OUT=`expr $NEWOUT – $OLDOUT`
fi
echo $IN
echo $OUT
date “+%H hours and %M minutes”
echo $1-email-count
echo $NEWIN > $INFILE
echo $NEWOUT > $OUTFILE
###################
# If you have problems with swap after MRTG is restarted, you don’t have to worry about that. If you don’t want to see those error messages, you can do this:
# Edit file:
#delete all lines and past the given lines
#!/bin/sh
TYPE=$1
PARAM=$2
if [ “$TYPE” = “load” ]; then
INDATA=`cat /proc/loadavg | cut -d ‘ ‘ -f2 | sed ‘s/\.//g’ | sed ‘s/^0//g’`
OUTDATA=`cat /proc/loadavg | cut -d ‘ ‘ -f3 | sed ‘s/\.//g’ | sed ‘s/^0//g’`
fi
if [ “$TYPE” = “processes” ]; then
INDATA=`cat /proc/loadavg | cut -d ‘ ‘ -f4 | cut -d ‘/’ -f 2`
OUTDATA=`cat /proc/loadavg | cut -d ‘ ‘ -f4 | cut -d ‘/’ -f 1`
fi
if [ “$TYPE” = “network” ]; then
LINE=`cat /proc/net/dev | grep $PARAM | sed s/$PARAM://`
INDATA=`echo $LINE | awk ‘{print $1}’ `
OUTDATA=`echo $LINE | awk ‘{print $9}’ `
fi
if [ “$TYPE” = “swap” ]; then
INDATA=`/usr/bin/free -b | grep “Swap:” | sed ‘s/ * / /g’ | cut -d ‘ ‘ -f2`
OUTDATA=`/usr/bin/free -b | grep “Swap:” | sed ‘s/ * / /g’ | cut -d ‘ ‘ -f3`
fi
if [ “$TYPE” = “uptime” ]; then
INDATA=`cat /proc/uptime | cut -d ‘ ‘ -f1`
OUTDATA=`cat /proc/uptime | cut -d ‘ ‘ -f2`
fi
if [ “$TYPE” = “tcp” ]; then
INDATA=`netstat -an | grep -c ESTABLISHED`
OUTDATA=$INDATA
fi
echo $INDATA
echo $OUTDATA
echo `uptime | cut -d”,” -f1,2`
echo $TYPE
##################