Server Monitoring With munin And monit On Debian Lenny

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2010-02-25 18:20. :: Debian | Monitoring

Server Monitoring With munin And monit On Debian Lenny

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 01/11/2010

In this article I will describe how you can monitor your Debian Lenny 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 Lenny, 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 Install And Configure munin

To install munin on Debian Lenny, we do this:

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


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 Tobias B. (not registered) on Thu, 2013-08-22 12:27.
Hi, as the attributes of /var/www/www.example.com/ directory changed to be not writable, the .htpasswd File must be created in /var/www/www.example.com/private/ So: vi /var/www/www.example.com/web/monitoring/.htaccess AuthUserFile /var/www/www.example.com/.htpasswd should be: AuthUserFile /var/www/www.example.com/private/.htpasswd and htpasswd -c /var/www/www.example.com/.htpasswd admin should be htpasswd -c /var/www/www.example.com/private/.htpasswd admin
Submitted by Ben (not registered) on Fri, 2010-03-05 12:33.
Why not use Cacti as an alternative ... it's much easier to set up (apt-get install cacti) and is managed through a web interface rather than editing conf files ... it has a massive community and a plugin architecture to make it monitor any device you want and configure alerts etc ...
Submitted by Gunnar (not registered) on Mon, 2010-08-16 23:05.

I strongly prefer Munin. First, it is way more versatile, it is very easy to create new plugins for it - As an example of all the things that can be graphed with a ~20 line script, take a look at DebConf's monitoring, i.e. the totals for our attendee database's requirements. Second, while Cacti is very strong on finding your network's topology and creating the needed graphs, it is IMO a bit more lacking for host-oriented graphs. Also, monitoring can involve some actions which require running with high privileges. It just is way safer to have all of your configuration in a root-controlled directory, not database-stored and modifiable through the Web interface.

Submitted by Andrei V. Toutoukine (not registered) on Mon, 2010-03-01 12:30.

munin @ Debian/lenny

Symptoms:  no pictures on http://www.example.con/monitoring after /etc/init.d/munin-node restart

Specify a hostname in /etc/munin/munin.node.conf:

 host_name server1.example.com

Restart munin again.

Submitted by shivlu jain (not registered) on Fri, 2010-02-26 06:40.

The post is wonderful. Have you written a article for NMS in linux. If yes, please the same.

 regards

 shivlu jain

 http://www.mplsvpn.info

Submitted by Klevo (not registered) on Mon, 2012-12-03 09:48.
Great
Submitted by Nikola (registered user) on Thu, 2010-02-25 20:13.

It would be any problem to use this guide with ispconfig 3?  I like various graphical monitoring tools ... :-)

Submitted by Toucan (registered user) on Wed, 2010-03-03 21:16.

Hi Nikola

I used this howto on ISPConfig3 Yesterday on a debian setup having install ISPConfig3 using the perfect server guide. It all worked well with just a couple of points to note.

When I added the site to be used for munin through the control panel it hadn't added www in front of the domain name so I needed to remove that throughout;

eg:

/var/www/www.yourdomain.com/web

becomes

/var/www/yourdomain.com/web

Then on the second page setting up monit, you'll have to comment out the lines regarding proftpd as ISPConfig3 uses pureftpd. If you don't monit will not start.

 Hope this helps

David

 

Submitted by Marlos (not registered) on Wed, 2010-03-10 23:29.

Hi guys,

now I using http://www.bijk.com for server performance monitoring and Alerts and i'm happy.

Bijk.com is FREE web-service for monitoring group of servers online, with online show performance graphs.

Bijk.com is ready for Cloud servers, Debian Servers and Ubuntu servers.

Submitted by Anonymous (not registered) on Sun, 2012-07-08 09:11.

Suggest you don't know what  "free" means.

 http://www.bijk.com/pricing

 

Submitted by Anonymous (not registered) on Sat, 2010-03-27 22:24.

unfortunately giving away login for a monitoring service will not be accepted by most security aware linux admins. why not publish your root login at facebook and ask your "friends" to monitor your server 

however, one more really interesting target.