How-To: Monitoring a Server with Munin

2 minute read

Munin is a simple to configure tool that make real nice graph about your server status. It can actually deal with almost any aspect of your server (load average, network cards status, CPU usage, memory usage, postfix, exim4, mysql …) without spending much time in configuring it.

Munin produce MRTG likes graph so you can easily see how your server health is going.

munin cpu graph munin ethernet graph This tutorial will show you how to set up Munin to gather statistics of a single server, but keep in mind that Munin can be deployed throughout a whole network, but beware that there is no real no security measure (such as authentication …) taken by munin.

To be able to access the datas gathered by munin, we are going to set up a virtual apache server. Those datas will only be accessible to authenticated users using apache mod_auth_digest (a more secure authetication protocol).

1. Installing and Configuring Munin

munin is composed of a master and client nodes. What happens basically, is that every client (node) runs munin-node and then the master regularly query the different node to gather and process datas.

1.1. Installing Munin

In our case, wa are going to run the master and the client on the same computer. The packages we need to install are munin and munin-node, so here we go, open a shell and type:

$ sudo apt-get install munin munin-node

Now that it is installed, it is about time to go and tweak up some files so we get a proper configuration.

1.2. Configuring the Master

First of all, we are going to edit the master file: /etc/munin/munin.conf. This is in this file that you define every clients the master is going to gather information from. As we use a simple model here, the only client the master is going to query information from is example.com which is accessible on adress 127.0.0.1.

So go and edit /etc/munin/munin.conf and make it look like:

dbdir       /var/lib/munin/
htmldir     /var/www/munin/
logdir      /var/log/munin
rundir      /var/run/munin/

[example.com]
        address 127.0.0.1
        use_node_name yes

So, what we have done here is to define munin working directories. htmldir for instance is the place where munin is going to store its graphs. Later on, we will have to set up an apache virtual server to be able to access those datas.

1.3. Configuring the Node

There is some basic security actions you can do while configuring the node.

Even though, by default, the node is configured to only authorized localhost to gather data from it, the nodes are listening on any networking interfaces.

As a security measure, we are going to change so the node bind itself to the loopback interface.

So go and edit /etc/munin/munin-node.conf and make sure the host value looks like this:

#host *
host 127.0.0.1

This is about all you need to do in order to get munin working.

As we modified the configuration, we need to restart the service with:

$ sudo /etc/init.d/munin-node restart

Next, we are going to set up apache in such a way that munin results are going to be accessible through web pages. But because we do not want everybody to access the stats, we are going to require authentication.