HOWTO: Compile, configure and run MRTG

ProWebUK

Verified User
Joined
Jun 9, 2003
Messages
2,326
Location
UK
As usual, i take no responsibility if anything goes wrong, the how-to assumes everything required is installed (GD, and a few perl modules - you will be notified if anything required is missing and provided with directions to help files by MRTG itself.

# lines starting with a '#' like this are to be used from command line

// text lines like these (starting with '//') are comments

=========

# wget http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/mrtg.tar.gz

# tar -zxvh mrtg.tar.gz

# cd mrtg*

# ./configure --with-gd=/usr/local/lib

# make

# make install

// now, if you did not recieve any error messages and everything went ok its time to get your cfg sorted and everything else setup.

// Please replace the /path/to/html/folder/ with the actual path to the html folder of the site which you wish to display the mrtg graphs at.

# cd /path/to/html/folder/mrtg/



# pico -w mrtg.sh

// paste the following code in the file:
// (Thanks to ryanz on the plesk forums for this)

#!/bin/sh

INFO=`grep eth0 /proc/net/dev | tr -s ' ' ' ' | cut -d: -f2`
RECEIVE=`echo $INFO | cut -d" " -f1`
TRANSMIT=`echo $INFO | cut -d" " -f9`
UPTIME=`uptime | tr -s ' ' ' ' | cut -d" " -f4-`
echo $RECEIVE
echo $TRANSMIT
echo $UPTIME
echo "yourdomain.com"

// CTRL and X to exit, press y to confirm the file save.

# chmod 755 mrtg.sh

// Now to create the CFG

# pico -w mrtg.cfg

WorkDir: /path/to/html/folder/mrtg/

Target[index]: `/path/to/html/folder/mrtg/mrtg.sh`
MaxBytes[index]: 25000000
Title[index]: Traffic and Load Analysis
PageTop[index]: <H1>Traffic and Load Analysis</H1>
Xsize[index]: 400
YSize[index]: 200


// nearly done!!
// now you can start it to see if its worked :)
// Check where mrtg is installed... it should be /usr/local/mrtg-2/
// if it is different replace the following paths appropiately

# /usr/local/mrtg-2/bin/mrtg /path/to/html/folder/mrtg/mrtg.cfg

// now depending what domain you used as the /path/to/html/folder go to the domain with a trailing mrtg, for example, if you used the path to the html folder of myfavdomain.com you would now go to:

http://myfavdomain.com/mrtg/index.html

you should see some pretty empty graphs :p

if thats the case, you can now add mrtg to cron to have it run every 5 minutes (or any other lengh you wish to use) to keep them graphs up2date.

# pico -w /etc/crontab

// after all the other lines enter this:

*/5 * * * * root /usr/local/mrtg-2/bin/mrtg /path/to/html/folder/mrtg/mrtg.cfg

// Please note the above line contains the same line used to start mrtg above, you can paste the line you used to start to speed things up slighly if you wish.

Now give it a few hours to notice the graphs in any detail. After just 1 hour you should start seeing data on your daily graph :)

Hope you enjoy this HOWTO guide :) any problems please feel free to post here.

Chris
 
Last edited:
I'm getting:
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work propperly when the environment
variable LANG is set to UTF-8. Please run mrtg in an environment
where this is not the case:

env LANG=C /usr/local/mrtg-2/bin/mrtg ...
-----------------------------------------------------------------------
when I run
Code:
/usr/local/mrtg-2/bin/mrtg /home/.............../mrtg.cfg
 
I chmodded 0755 mrtg.sh and prepended
Code:
WorkDir: /path/to/html/folder/mrtg
to mrtg.cfg and all appears to be working.

Thanks Chris! :)


Edit: MRTG is really cool :p www.liquenox.net/mrtg :)
 
Last edited:
check your mrtg.cfg, it should be:


##################################
WorkDir: /path/to/html/folder/mrtg/

Target[index]: `/path/to/html/folder/mrtg/mrtg.sh`
MaxBytes[index]: 25000000
Title[index]: Traffic and Load Analysis
PageTop[index]: <H1>Traffic and Load Analysis</H1>
Xsize[index]: 400
YSize[index]: 200
#################################

(without the # ;) )

Tell us how that goes, or if its already in your cfg.

Chris
 
worked just perfect, i also had to chmod the mrgt.sh file, but after that no problemo...
On my cpanel and ensim boxes i have a "full" mrtg with all the graphs, and i miss a few of them here - anyone with a howto on the full setup?

thanks :)
 
dont currently have them for DA, you may want to check the CFG's being used on your Cpanel / Ensim systems and try to convert them to work with DA.

If you get them to work it would be brilliant if you could post them here for the other DA users ;)

Chris
 
I was referring to joker's sentence : "On my cpanel and ensim boxes i have a "full" mrtg with all the graphs, and i miss a few of them here - anyone with a howto on the full setup?"
To which you answered that it needed to be converted
 
interfasys said:
Did anybody succesfully create a full graph config for DA?



http://download.cheetaweb.com/mrtg-2.9.17-1cpanel.i386.rpm


Install that.. Then alter /etc/mrtg/mrtg.cfg

Change the WorkDir to: /var/www/html/mrtg

Save and exit.. Then mkdir /var/www/html/mrtg


You can then setup an alias to the graphs the same way webmail and phpmyadmin works...


I've never built an RPM so I'm not gonna bother trying to :)
 
interfasys said:
Since I already have mrtg installed, I guess I'll be better off finding a .cfg from the web, no?


You could.. But you need the scripts that get the stats from the server :)

Easies would be to just remove the current RPM and install the new one... Its a stock MRTG binary...
 
*/5 * * * * /usr/local/mrtg-2/bin/mrtg /path/to/html/folder/mrtg/mrtg.cfg

does not work for me (command works from console though)

Any idea on how to run the script every 5 minutes?

I mean should I use this one instead :
*/5 * * * * root /usr/local/mrtg-2/bin/mrtg /path/to/html/folder/mrtg/mrtg.cfg
?
 
interfasys said:
*/5 * * * * /usr/local/mrtg-2/bin/mrtg /path/to/html/folder/mrtg/mrtg.cfg

does not work for me (command works from console though)

Can i ask where you added the line?
 
Back
Top