Setting up Munin on Ubuntu
Summary
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/^/#/ <enter> :wq <enter>
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!