HOWTO: Install MRTG (FULLY AUTOMATED)

loopforever

Verified User
Joined
May 30, 2003
Messages
298
Location
/home/admin
Hi Guys,

** June 6th. 2008: MRTG tarball location has been updated to reflect it's new home on the official MRTG site. Also worth noting, I haven't updated this thread since 2005. Jeeze...you guys have been using this thing for a while!

With the addition of a new server I found myself in the position of installing MRTG again. Chris (ProWebUK) wrote up a nice guide for installing MRTG manually - but I found the config to be lacking in some of the features I needed to monitor.

So, I grabbed the mrtg.cfg from an old CPanel rpm and modified it slightly to work on a DA machine. The script I wrote will automatically download and install the latest version of MRTG and apply a very nice config for your viewing pleasure. Please note...I take ABSOLUTELY no credit for the mrtg.cfg included - I simply made a small modification and wrote an installer for the whole process.

The installer will check to see if you have anything installed in /var/www/html/mrtg - if you have mrtg installed in another directory, you should remove it first. If you are already running MRTG, you need to make sure you delete it and its crontab entry before continuing with the installer.

Guide:
Code:
wget [url]http://serveio.com/da/install.mrtg.sh[/url]
chmod +x install.mrtg.sh
./install.mrtg.sh
When the process is done MRTG will be installed in:

/var/www/html/mrtg

and can be viewed at:

http://your.hostname.com/mrtg

You can see the output of my install at:

http://loop.serveio.com/mrtg

Enjoy!

Confirmed Supported OSs:

RedHat 9
Fedora Core 3
Fedora Core 2
Debian 3.0
CentOS 3.4
CentOS 4.0

If this installer works properly for you, please let me know what OS you used so I can update this list!

Uninstall Instructions

For those of you that want to uninstall MRTG (assuming you used this installer), please follow these steps:
  • Open /etc/crontab and remove the line that reads:
    */5 * * * * root /usr/local/mrtg-2/bin/mrtg /var/www/html/mrtg/core/mrtg.cfg
  • rm -rf /usr/local/mrtg-2/
  • rm -rf /var/www/html/mrtg/
 
Last edited:

jmstacey

Verified User
Joined
Feb 12, 2004
Messages
4,107
Location
Colorado
Just installed it and working perfectly on Debian 3.0

Thanks for the script loopforever :D
 

loopforever

Verified User
Joined
May 30, 2003
Messages
298
Location
/home/admin
Great! If you install it on any other OSs, let me know. I'll keep a list of confirmed operating systems for everyone's reference.
 

loopforever

Verified User
Joined
May 30, 2003
Messages
298
Location
/home/admin
It would be helpful if you provided the output of the install script whereever errors occurred. Do you even know if it gave you an error?

You also must access the mrtg directory through your servers host name or IP. Not a Vhost in your httpd.conf.

Try:

http://serverip/mrtg

And if that doesn't work, please tell me what errors the install script produced.
 

loopforever

Verified User
Joined
May 30, 2003
Messages
298
Location
/home/admin
You cannot access files in your global html directory through vhosts. Vhosts direct you to shared accounts on a given IP. The only way to access anything in the global html directory is through any ip or domain that is pointing to your server but does not have a virtualhost configured. You can add an A record (infact...you should most definitely add an A record) that points hostname.yourdomain.com -> yourip.
 

jmstacey

Verified User
Joined
Feb 12, 2004
Messages
4,107
Location
Colorado
You could add an alias to the httpd.conf file so that it would be like /webmail /squirrelmail etc and accessible on all domains.
 

Icheb

Verified User
Joined
Sep 15, 2003
Messages
556
Location
The Netherlands
I usually get the following warnings:
Executing MRTG for the first time (you may see some warnings)...
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
variable LANG is set to UTF-8. Please run mrtg in an environment
where this is not the case. Try the following command to start:

env LANG=C /usr/local/mrtg-2/bin/mrtg /var/www/html/mrtg/core/mrtg.cfg
-----------------------------------------------------------------------
If you see warnings above, it is generally safe to ignore.


Perhaps it's an idea to add the env LANG=C thingy to the crontab to avoid getting this error too much :).
(Although I don't know if this is also required on all systems :D)

I looked at the network stats script, it's interesting that it uses not snmpd but the /proc data.

Edit:
Furthermore I get the following error on the server I installed this on to test it:
[root@montu root]# env LANG=C /usr/local/mrtg-2/bin/mrtg /var/www/html/mrtg/core/mrtg.cfg
/var/www/html/mrtg/core/system: line 1: 546200-507712: command not found
WARNING: Problem with Externale get '/var/www/html/mrtg/core/system swap':
Expected a Number for 'out' but got ''

ERROR: Target[swap][_OUT_] ' $target->[3]{$mode} ' did not eval into defined data
 
Last edited:

loopforever

Verified User
Joined
May 30, 2003
Messages
298
Location
/home/admin
I will take a look at the LANG bit - I know that may be a bit of an issue for some people. Thanks for bringing it to my attention.

Also, regarding your "swap" error. This is the section of the system file which I rewrote because /proc/meminfo can vary from distro to distro. What OS are you trying to install on, and can you provide me the output of:

cat /proc/meminfo

Thanks!
 

Icheb

Verified User
Joined
Sep 15, 2003
Messages
556
Location
The Netherlands
I fixed the error by editing the system bash file; on some line in the swap part it calculates the amount of used swap. The way it calculates this is wrong for my bash version (most versions, I hope).

Edited that part so that it reads:
if [ "$TYPE" = "swap" ]; then
SWAPFREE=`cat /proc/meminfo | grep "SwapFree" | sed 's/ //g' | cut -d ':' -f2 | cut -d 'k' -f1`
SWAPTOTAL=`cat /proc/meminfo | grep "SwapTotal" | sed 's/ //g' | cut -d ':' -f2 | cut -d 'k' -f1`
SWAPUSED=`expr $SWAPTOTAL - $SWAPFREE`
INDATA=$SWAPFREE
OUTDATA=$SWAPUSED
fi
Now it works fine :)
(calculating in bash should use the expr program instead of directly trying it in bash, in my opinion).

And for your pleasure:
[root@montu core]# cat /proc/meminfo
total: used: free: shared: buffers: cached:
Mem: 494739456 479768576 14970880 0 76853248 131510272
Swap: 559308800 22380544 536928256
MemTotal: 483144 kB
MemFree: 14620 kB
MemShared: 0 kB
Buffers: 75052 kB
Cached: 108140 kB
SwapCached: 20288 kB
Active: 198612 kB
Inactive: 218064 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 483144 kB
LowFree: 14620 kB
SwapTotal: 546200 kB
SwapFree: 524344 kB
edit: corrected an error, added some fat text to make it a bit more clear what I did...
 

loopforever

Verified User
Joined
May 30, 2003
Messages
298
Location
/home/admin
DOH!

Very cool - I apologize for that...I was on my way out the door from work when I slopped those two commands together. I will update the system file in my tarball for future uses.

Thanks!

Edit: Tarball has been updated with a revised system file!
 
Last edited:

servertweak

Verified User
Joined
Feb 3, 2005
Messages
294
works great , thank you

Great running on CentOS 3.4 and CentOS 4.0
 
Last edited:

neorder

Verified User
Joined
Oct 1, 2003
Messages
392
this is just great! i did try to speed time how to add more things to monitor in mrtg, but was not successful.

thanks.loopforever, you are one of the professionals here also!
 

CEpeep

New member
Joined
Apr 27, 2005
Messages
4
Working well on CentOS 3.4.

Is there any way I can get it to display my bandwidth in bits instead of bytes though? I tried adding "bits" to the options string in the cfg, but it didn't change anything. It's sort of a pain to have to multiply everything by 8 when I want to figure out how much of my pipe I'm using.

EDIT: I figured it out. Had to add it to the traffic options, not global options.
 
Last edited:

Icheb

Verified User
Joined
Sep 15, 2003
Messages
556
Location
The Netherlands
Btw: I don't know if anyone is interested in it, I've been working with MRTG for ages.
I've used this setup on one of my servers and am slowly adding more and more stats to it, if you are interested I'm willing to pm the specs so that they can be included in future releases.
At the moment the main addition is a Apache hit counter. (Total hits on server per hour)

When I have some more time, I'll add some other stuff as well :).
 

loopforever

Verified User
Joined
May 30, 2003
Messages
298
Location
/home/admin
Icheb - That would be a great addition. I also so mention in another thread of a script that outputs mysql process information. I think these are two features we can easily include in the install script. With the addition of these I will also fix the bug that is report CPU usage incorrectly.

I'll try and get in touch with you shortly to put your Apache hit counter in the "system" script.
 

jmstacey

Verified User
Joined
Feb 12, 2004
Messages
4,107
Location
Colorado
Which stats Weccop?
mrtg - hostname.domain.com/mrtg
apache hit counter - probably requires a new configuration for mrtg it possible.
 
Top