February 17, 2010

Setting up Munin on Ubuntu

Posted in Software at 06:50 by graham

Munin is a system monitoring tool. It produces graphs for Apache, MySQL, Nginx, CPU, Memory, Disk, etc. Example munin installation – Live.

Here are my notes from setting it up, they are brief, but should help you get going.

All the monitored machines run a small daemon called munin-node. One machine is the central server. Every few minutes it gathers data from all the nodes (including itself), generates the graphs, and writes out some HTML files.

In my case I have a proxy running Nginx and acting as the Munin central server, and two nodes each with Apache and MySQL.

Everything that Munin monitors is in a separate plugin. Most of the ones you’ll need are bundled, but might need switching on.

If you only have one machine, that is your only node. Do both steps on that machine.

On each node

sudo apt-get install munin-node munin-plugins-extra

Edit /etc/munin/munin-node.conf and add these lines:

host_name mynode.mydomain.com  # Hostname of the node machine
allow 192.168.122.201   # IP address of the central server
host 192.168.122.203    # Host IP address

If your Apache is not on port 80, edit the plugin config file /etc/munin/plugin-conf.d/munin-node and change or add these lines:

[apache_*]
env.url   http://127.0.0.1:%d/server-status?auto
env.ports 81

Link the Apache plugin (it may already be linked, no problem)

cd /etc/munin/plugins/
sudo ln -s /usr/share/munin/plugins/apache_processes apache_processes

Switch on Apache ExtendedStatus

sudo vi /etc/apache2/mods-available/status.conf

Outside of the Location section, add ExtendedStatus On

<IfModule mod_status.c>

ExtendedStatus On
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost ip6-localhost
</Location>

</IfModule>

Install the Perl www packages (the Munin Apache plug needs them):

sudo apt-get install libwww-perl

Bounce munin-node and apache

sudo /etc/init.d/munin-node restart
sudo /etc/init.d/apache2 reload

On the central server

sudo apt-get install munin munin-node munin-plugins-extra

Setup a crontab to run the data gathering task every five minutes

sudo -u munin crontab -e

Add this line

*/5 * * * *     /usr/bin/munin-cron

Edit /etc/munin/munin.conf and set the nodes you want to gather data from, and their IP addresses.

[central.mydomain.com]
    address 127.0.0.1
    use_node_name yes

[node1.mydomain.com]
    address 192.168.122.203
    use_node_name yes

[node2.mydomain.com]
    address 192.168.122.202
    use_node_name yes

Run it!

sudo -u munin munin-cron

Look in /var/www/. You should see a munin directory.

Setup your web server to point to the HTML files. If like me you’re using Nginx, edit /etc/nginx/sites-available/mydomain.com, and add these lines

location /munin/ {
    root /var/www/;
    expires off;
    auth_basic "Munin";
    auth_basic_user_file /etc/nginx/.htpasswd;
     }

Create the htpasswd file, or see password protecting a folder with Nginx.

htpasswd -c /etc/nginx/.htpasswd username

Try it out, by browsing to http://myserver.com/munin. myserver.com is of course the address your Nginx is serving.

You should see some graphs, but they will be blank, or display Nan instead of numbers. Be patient. In 10 – 15 minutes Nan will be replaced by numbers, and the graphs will slowly start appearing.

Add nginx monitoring

A bit of fancy footwork required here. This might of improved by the time you read this.

sudo apt-get install libwww-perl

Download Munin plugins nginx request and nginx status.

Replace the very first line of each one, the one that says @@PERL@@ with this line

#!/usr/bin/perl -w

Comment out the rest of the header. Open the file in vim, hit Esc, and type

:3,56s/^/#/  
:wq 

Note: I’m obviously missing an install step here. If you know, please help me in the comments

Copy the plugins into munin’s available plugins directory

cp nginx_request /usr/share/munin/plugins
cp nginx_status /usr/share/munin/plugins
sudo chmod ug+x /usr/share/munin/plugins/nginx_*

Edit your nginx config to switch on status. Edit /etc/nginx/sites-available/mydomain.com and add these lines:

location /nginx_status {
        stub_status on;
        access_log   off;
        #allow 127.0.0.1;
        #deny all;
        allow all;
    }

Restart nginx: sudo /etc/init.d/nginx restart

Link the plugins into the active plugins directory

cd /etc/munin/plugins/
perl nginx_request autoconf

sudo ln -s /usr/share/munin/plugins/nginx_request nginx_request
sudo ln -s /usr/share/munin/plugins/nginx_status nginx_status

And you should be set. Happy monitoring!

7 Comments »

  1. bryan forst said,

    May 30, 2013 at 11:47

    On my install the default for munin www files are now in

    /var/cache/munin/www

    list of defaults are in the munin.conf file….

    Thanks for this easy checklist, a big help…

  2. Trish said,

    October 15, 2012 at 17:14

    Hi there! Thanks for the documentation! I have Munin running successfully now and monitoring two servers. I wanted to add two additional servers though, and added them as nodes in /etc/munin/munin.conf like:

    [node2.mydomain.com] address 192.168.122.202 use_node_name yes

    From here though, how do I get Munin to add them and start generating web templates? I tried running both sudo -u munin munin-cron and sudo /etc/init.d/munin-node restart, but the web templates remain the same. Is there a command to force Munin to purge and rebuild all the web templates?

  3. Ale said,

    September 10, 2012 at 18:06

    it works!!!!

  4. Harry Wood said,

    November 8, 2011 at 12:49

    On the node machine you can test if a munin plugin is working with a command like this:

    munin-run apache_processes

    This should spit out the same data that munin receives every 5 minutes to plot the graph.

    Right now I’m trying to work out why I’m getting nothing but ‘U’ values from the apache_processes munin plugin, resulting in an empty graph. Any suggestions?

  5. Lau said,

    December 29, 2010 at 17:03

    I just had a second go at getting Nginx working and found a new nginx_combined plugin:

    http://exchange.munin-monitoring.org/plugins/nginx-combined/details

    Usage information is in the Perl file. Throw the file in the plugins folder og symlink the combined plugin in as nginx_combined_[hostname]

    Remember to set up stub_status on the same host as specified in the symlink.

  6. Duncan McQueen said,

    September 11, 2010 at 17:54

    Looks good, but you need to reverse the linking steps – you need the nginx_status in the directory when you run perl autoconf.

    So, it should be like this:

    cd /usr/share/munin/plugins/ perl nginx_request autoconf

    cd /etc/munin/plugins/ sudo ln -s /usr/share/munin/plugins/nginx_request nginx_request sudo ln -s /usr/share/munin/plugins/nginx_status nginx_status

  7. Daniel Bachhuber said,

    September 9, 2010 at 21:21

    Thanks for the documentation! Munin tutorials are pretty sparse. Were you able to get Nginx monitoring working?

Leave a Comment

Note: Your comment will only appear on the site once I approve it manually. This can take a day or two. Thanks for taking the time to comment.