This is a "copy & paste" HowTo! The easiest way to follow this tutorial is to use a command line client/SSH client (like PuTTY for Windows) and simply copy and paste the commands (except where you have to provide own information like IP addresses, hostnames, passwords,...). This helps to avoid typos.

Server Monitoring With munin And monit

Version 1.0
Author: Falko Timme
Last edited 04/20/2006

In this article I will describe how to monitor your 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 Debian Sarge, 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 Current Situation

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 Install And Configure munin

To install munin on Debian Sarge, we do this:

apt-get install munin munin-node

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

tmpldir /etc/munin/templates

[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...)

3 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!

Share this page:

18 Comment(s)

Add comment

Comments

From: Anonymous at: 2006-04-23 19:39:31


Excellent, and straightforward tutorial.

Remember that the munin logs are located in /var/log/munin/

It can be a while before new graphs are generated. The default configuration will fail.

From: Anonymous at: 2006-04-23 11:42:19


Munin works just fine out of the box.

But yo must consider when graphing the cpu temp, it rises by 4C at the time munin is running, on a P3 1GHz.

My workaround is to check cpu temp 1min before munin runs an put into a clear text file :)


From: Anonymous at: 2006-05-08 16:21:44


Another application that does all this easily is www.bixdata.com. Plus it also runs on windows if you need to monitor that.

From: Anonymous at: 2006-05-08 02:52:27


Dont you need to get apache to work with this? I had to edit conf.d/xxxx.conf in order to get /monitoring/ to link.

eg.,

Alias /monitoring/ /var/www/www.xxxx.dyndns.org/web/monitoring/
#ScriptAlias /monitoring/ /var/www/www.xxxx.dyndns.org/web/monitoring/
<Directory /var/www/www.xxxx.dyndns.org/web/monitoring/>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

Then it worked fine, unless I have missed something???

regards


From: Anonymous at: 2006-05-09 12:41:27


It would be nice if you also provided the links to the official sites of the applications...

From: admin at: 2006-05-10 09:37:14
From: Anonymous at: 2006-06-22 21:08:29

hi, i agree that by default that the .htaccess file didn't work on Debian Sarge. Instead i just copied what was in the file to the main configuration (apache2.conf) and enclosed it in a < Directory > container
e.g.


< Directory /var/www/www.example.com/web/monitoring >
AuthType Basic
AuthName "Password Required"
AuthUserFile /var/www/www.example.com/.htpasswd
limit GET PUT POST
require valid-user
< /limit >
< /Directory >



and then I follwed the remaining steps to make the .htpasswd file and it worked perfectly!

Thanks for the great Howto!

From: Bjoern at: 2009-02-09 02:05:20

Hi there,


 another good monitoring tool in my opinion is Zabbix. Though there are plenty around, this is very interesting:


 http://en.wikipedia.org/wiki/Comparison_of_network_monitoring_systems


 Cheers

From: Anonymous at: 2010-05-24 18:00:04

 Also uncomment the following lines:

 

       AuthUserFile /etc/munin/munin-htpasswd

AuthName "Munin"

AuthType Basic

require valid-user

 

Save and close

 

sudo htpasswd -c /etc/munin/munin-htpasswd admin

 


sudo service apache2 restart

 

 Done!

From: at: 2011-12-02 21:36:09

I run mysql as a local service with the port closed. How do I configure monit for that?

From: Anonymous at: 2006-05-08 15:10:44


I got into work at 8:30 am this morning. I read this article at 9am.

By 9:30 I was running both monit and munin on a test server.

Awesome!


From: Anonymous at: 2006-05-08 18:42:02


I recommend you http://www.monitorix.org. It is a very easy to install web-based, lightweight, open-source, rrdtool-based monitoring tool for UNIX and Linux servers that you must try.

:-)

From: Anonymous at: 2006-05-08 18:59:53


Thanks for the detailed instructions. I had both of them running in about an hour. Thanks!

From: Anonymous at: 2006-06-13 16:07:10


Thanks for the great howto. It works great and was up and running in less than 1 hour.

From: Anonymous at: 2006-07-31 16:29:31

I set up both of them in less than 30 min.

However, I am wandering what "10" in this statement means:

"if loadavg(5min) greater than 10 for 5 cycles then stop"

I do receive very often notifications about apache restart...?

From: Mattia Belletti at: 2009-09-08 12:55:28

Thank you! Very useful and straight-to-the-point!

From: Ventzy at: 2010-06-22 16:26:57

How much additional server load can be expected of running munin and monit?


Is it possible monit to monitor another server, so if whole server is down to get notified?

From: Anonymous at: 2014-07-16 07:15:59

Above it, it defines stop with: stop program = "/etc/init.d/apache2 stop"

So I think it (the "10") means



"If the average load for the last 5 mins is > 10 for 5 runs, then stop apache



Above that, it says: set daemon 60

This sets Monit to run every minute (60 seconds)

So if the average load for the last 5 mins is more than 10, for 5 minutes straight, it stops apache