Monitoring Your Debian Or Ubuntu Server With Munin
Monitoring your server’s performance and activity is one of the duller aspects of running a server, and often something that is overlooked until there is a problem. Fortunately, there are many tools that can be used to monitor your server’s resources with differing levels of complexity and difficulty to configure. One of the simpler tools is Munin, which we are going to look at today.
What is Munin?
Munin is a networked monitoring tool, meaning that it can be used to monitor multiple servers if required. It can store data and plot graphs with the stored data, allowing you to not only see what is happening now but also historically. Munin consists of multiple parts, the master (which is installed on the server on which you wish to view data) and node (which is installed on servers to send data to the master). In this guide, we will focus on installing the master and monitoring the server it is installed on.
Installing Munin
For this guide, we’ll assume you have a server with Ubuntu or Debian Linux distributions running. We also require that you have the Apache web server installed. We’ll need some perl CGI mods installed:
sudo apt-get update
sudo apt-get install libcgi-fast-perl libapache2-mod-fcgid
With those installed we need to ensure that fcgid is enabled:
sudo a2enmod fcgid
The next step is to install Munin itself:
sudo apt-get install munin munin-node munin-plugins-extra
Munin Configuration
With Munin installed we now need to configure it for use. All of Munin’s configuration data is stored in the /etc/munin directory. The first file we’ll look at is the munin.conf file:
sudo nano /etc/munin/munin.conf
This is a well-commented file that explains what it does quite clearly. If you need to make any custom changes then the default values should be adequate for you. For now, we just need to uncomment (remove the # at the start) the lines starting with the following:
dbdir
htmldir
logdir
rundir
tmpldir
Save and exit the file once the changes are made. Once that’s done, the next thing to configure is how Apache will serve the pages for your Munin instance. This is done with either the apache.conf file or the apache24.conf file in the Munin configuration directory. The default configuration is generally fine, but it only allows access from the local system which isn’t much help if you want to monitor your server remotely. To identify which file you’ll need to modify you’ll need to know which version of Apache you are using. This information can be found with the following command:
apache2 -v
Look for the line stating “Server version:”. If it is 2.4.0 or higher (which should be most current distributions) then you need to edit the apache24.conf file, otherwise the apache.conf file is used. We’ll start by looking at the apache24.conf file for those who need to edit it:
sudo nano /etc/munin/apache24.conf
There are two sections in the file, and each has a “Require” statement in them. By default, this is set as “Require local” which means only local users can see the page. As it’s best practice not to allow the world to see your monitoring data, we can change that line to “Require ip 1.2.3.4”, changing 1.2.3.4 for the IP address that you will be connecting from. Save and exit the file, then reload the Apache configuration with:
systemctl reload apache2
Now if you browse to http://yourdomain.com/munin or http://1.2.3.4/munin (replacing yourdomain.com with your server’s domain name, or 1.2.3.4 with your server’s IP address), you will be able to see the Munin monitoring on your server.
For those using an older version of Apache, let’s now look at the apache.conf file:
sudo nano /etc/munin/apache.conf
This file will contain 3 sections with “Allow” statements in them, which will look like “Allow from localhost, 127.0.0.0/8 ::1″. Similar to with the apache24.conf file, adding the IP address that you are connecting from to the end of this line will allow you to connect to the server. So, add your IP address to all of those “Allow” statements, then save and exit the file. Then restart Apache, however, with an older version of Apache it’s likely you’ll need to use the following command:
sudo service apache2 reload
You can then browse to Munin on your website as described above.
Once you have opened the Munin page for your server you will see that it shows lots of information on how it is running. You can monitor more elements on the server or add additional servers to monitor later, something we’ll be looking at in another article. We’d recommend adjusting the Apache settings for your Munin pages to include password authentication to access them.