Server Monitoring With munin And monit On CentOS 5.2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Mon, 2008-12-01 18:08. :: CentOS | Monitoring

Server Monitoring With munin And monit On CentOS 5.2

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 11/11/2008

In this article I will describe how you can monitor your CentOS 5.2 server with munin and monit. munin produces nifty little graphics about nearly every aspect of your server (load average, memory usage, CPU usage, MySQL throughput, eth0 traffic, etc.) without much configuration, whereas monit checks the availability of services like Apache, MySQL, Postfix and takes the appropriate action such as a restart if it finds a service is not behaving as expected. The combination of the two gives you full monitoring: graphics that lets you recognize current or upcoming problems (like "We need a bigger server soon, our load average is increasing rapidly."), and a watchdog that ensures the availability of the monitored services.

Although munin lets you monitor more than one server, we will only discuss the monitoring of the system where it is installed here.

This tutorial was written for CentOS 5.2, but the configuration should apply to other distributions with little changes as well.

I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

Our system's hostname is server1.example.com, and we have a web site www.example.com on it with the document root /var/www/www.example.com/web.

 

2 Enable The RPMforge Repository

On CentOS 5.2, munin and monit are not available in the default CentOS repositories. Fortunately we can install them from the RPMforge repository. To enable the RPMforge repository, we run

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

rm -f rpmforge-release-0.3.6-1.el5.rf.i386.rpm

on i386 hosts and

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

rm -f rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

on x86_64 hosts (please check out https://rpmrepo.org/RPMforge/Using for the latest versions).

 

3 Install And Configure munin

To install munin on CentOS 5.2, we do this:

yum install munin munin-node

Then we create the system startup links for munin and start it:

chkconfig --levels 235 munin-node on
/etc/init.d/munin-node start

Next, we must edit the munin configuration file /etc/munin/munin.conf. We want munin to put its output into the directory /var/www/www.example.com/web/monitoring, therefore we change the value of htmldir, and we want it to use the name server1.example.com instead of localhost.localdomain in the HTML output, therefore we replace localhost.localdomain with server1.example.com. Without the comments, the changed file looks like this:

vi /etc/munin/munin.conf

[...]
dbdir   /var/lib/munin
htmldir /var/www/www.example.com/web/monitoring
logdir  /var/log/munin
rundir  /var/run/munin

# Where to look for the HTML templates
tmpldir /etc/munin/templates
[...]
# a simple host tree
[server1.example.com]
    address 127.0.0.1
    use_node_name yes
[...]

Next we create the directory /var/www/www.example.com/web/monitoring and change its ownership to the user and group munin, otherwise munin cannot place its output in that directory. Then we restart munin:

mkdir -p /var/www/www.example.com/web/monitoring
chown munin:munin /var/www/www.example.com/web/monitoring
/etc/init.d/munin-node restart

Now wait a few minutes so that munin can produce its first output, and then go to http://www.example.com/monitoring/ in your browser, and you see the first statistics. After a few days this could look like this:

(This is just a small excerpt of the many graphics that munin produces...)

 

4 Password-Protect The munin Output Directory (Optional)

Now it is a good idea to password-protect the directory /var/www/www.example.com/web/monitoring unless you want everybody to be able to see every little statistic about your server.

To do this, we create an .htaccess file in /var/www/www.example.com/web/monitoring:

vi /var/www/www.example.com/web/monitoring/.htaccess

AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/www.example.com/.htpasswd
<limit GET PUT POST>
require valid-user
</limit>

Then we must create the password file /var/www/www.example.com/.htpasswd. We want to log in with the username admin, so we do this:

htpasswd -c /var/www/www.example.com/.htpasswd admin

Enter a password for admin, and you're done!


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by royalcharlie (not registered) on Fri, 2011-02-18 13:25.

Followed instructions and encountered a problem that just got solved due to comments from an anonymous. Many thanks to you!

Am using centos 5.5 64-bit.
and only changed htmldir to /var/www/html/munin

Waited for a while and checked via browser only to get a link to localhost and that's it. Nothing else is displayed. Checked the logs and the munin directory itself and there are files being created. Tried rebooting but no effect.

Read through the steps again and this time including the comments and read about editing /etc/httpd/conf.d/munin.conf and noticed that the alias is pointing to /var/www/munin rather than /var/www/html/munin.

After changing this and restarting apache daemon... the munin site is working. Cheers.

Submitted by ahmet (not registered) on Tue, 2011-08-30 20:38.
This is my working way if you have more then one web site
Centos 6.0

vim /etc/munin/munin.conf

 dbdir  /var/lib/munin
 htmldir /var/www/html/munin
 logdir /var/log/munin
 rundir  /var/run/munin
#
# Where to look for the HTML templates
 tmpldir    /etc/munin/templates

# (Exactly one) directory to include all files from.
#
includedir /etc/munin/munin-conf.d

# a simple host tree
#[x86-10.phx2.fedoraproject.org]
#    address 127.0.0.1
#    use_node_name yes

[www.example.com]
    address 127.0.0.1
    use_node_name yes



vim /etc/httpd/conf/httpd.conf


DocumentRoot "/var/www/html/munin"
ServerName monin.example.com
<Directory "/var/www/html/munin">
allow from all
Options +Indexes
</Directory>



Enter http://monin.example.com/

 
Submitted by jindowin (not registered) on Sun, 2009-05-03 09:14.

i get error when i type to my browser:

Not Found

The requested URL /monitoring/ was not found on this server.


Apache/2.2.3 (CentOS) Server at www.example.com Port 80
 
 
can u help me? do i need install apache before install munin?

 

Submitted by Haider (not registered) on Fri, 2009-02-27 17:27.

Hello 

 

I'd installed munin monitoring tool in centos 5.2

I'd completed all the step, but when i open my web browser and try to access 

www.example.com 

i get error 

NOT Found

The Request URL/ monitoring/ was not found on this server

Can u please help me out 

 

Submitted by Anonymous (not registered) on Sun, 2009-02-01 17:46.

By changing the ownership to munin you are unable to see the content. Also you need to include /html

Submitted by jindowin (not registered) on Sun, 2009-05-03 09:07.

can u help me clearly?

i get error the same..but i dont know where i have to "include /html"

Submitted by Matthew (not registered) on Mon, 2009-05-11 14:07.

Latest packages of munin place html to /var/www/html/munin

nano /etc/httpd/conf.d/munin.conf    and paste the following (change *  to the ip of your pc)

 Alias /monitoring /var/www/html/munin

<Location /usage>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    Allow from *.*.*.*
</Location>

 

 +After restart Apache deamon

service httpd restart

Submitted by Anonymous (not registered) on Sat, 2010-05-29 03:56.
These steps are not solving problem with the munin install on centos. I tried and go through each step but same result. Its giving me the same error as mention aboved. So it means these steps are not worth it. Dont follow these steps.
Submitted by Anonymous (not registered) on Thu, 2010-06-03 08:40.

I don't mean to be rude, but if you can't figure this out I don't know if you will have any luck using the stats this produces.

 Let's pretend you have a Vhost in apache called mycoolsite.com with a docroot of /www/mycoosite.com/docs

 Ok... all you do is create a directory called /www/mycoolsite.com/docs/monitoring

Change ownership and group to munin or just do chmod 777 monitoring

 Munin will put html/image files inside whatever directory you tell it to in the config, and you access it by putting in the web address to that directory (in this case www.mycoolsite.com/monitoring)

 Bottom line, create a new directory inside of a website you already have setup and running, then set the munin conf to use that directory, then access the stats by accessing that website/directory.

Submitted by tracepath (not registered) on Tue, 2010-10-19 16:35.

I followed all steps but i have i problem. The output folder is /var/www/html/egw/web/monitoring and when i put "hostname.server.com/egw/web/monitoring" is empty. No charts.

 What can i do ?

Thanks