This is a short tutorial on setting up munin to monitor your Django website on ec2.
We're gonna be using Nginx instead of apache here because it's more lightweight and popular between Django developers.
1. Install munin ''''''''''''' :
# amend nginx if it's already installed
sudo apt-get install munin munin-node nginx
2. Edit /etc/munin/munin-node.conf ''''''''''''' :
host_name my.hostname.com
allow ^.*$
3. Edit /etc/munin/munin.conf ''''''''''''' :
[my.hostname.com]
address domU-00-00-00-00-00-00.compute-1.internal
Where 'my.hostname.com' is a node you're going to monitor and 'domU-00-00-00-00-00-00.compute-1.internal' is an internal address of the ec2 instance this node is hosted on.
4. Edit /etc/nginx/sites-available/stats.hostname.com '''''''''''''
Assuming 'stats.hostname.com' is where you want your munin monitoring dashboard to be:
server {
listen 80;
server_name stats.hostname.com;
location / {
root /var/cache/munin/www;
}
}
5. Enable this nginx site and restart nginx ''''''''''''' :
sudo ln -s /etc/nginx/sites-available/stats.hostname.com /etc/nginx/sites-enabled/
sudo /etc/init.d/nginx restart
6. Open http://stats.hostname.com/ in your browser '''''''''''''
If everything worked you should see your basic munin interface with information about disk, munin, network, processes, squid and system:
7. (Optional) If you want to protect your dashboard with basic HTTP auth you need to generate a htpasswd file in /etc/nginx/ ''''''''''''' :
sudo echo -e "your-username:`perl -le 'print crypt("your-password","salt")'`" > /etc/nginx/htpasswd
If you don't have permissions to do that, just use the first part of the expression to generate an encrypted password and create htpasswd manually. You can also use .htpasswd file Generator .
You'll need to update /etc/nginx/sites-available/stats.hostname.com:
server {
listen 80;
server_name stats.hostname.com;
location / {
root /var/cache/munin/www;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
}
Restart nginx again:
sudo /etc/init.d/nginx restart
Now munin is password protected.
8. Enable any pre-installed munin plugins you might need '''''''''''''
You can see a list of available plugins by:
ls /usr/share/munin/plugins/
To enable any plugin just symlink it to /etc/munin/plugins/. For example, let's enable mysql and postfix plugins:
sudo ln -s /usr/share/munin/plugins/mysql* /etc/munin/plugins/
sudo ln -s /usr/share/munin/plugins/postfx* /etc/munin/plugins/
9. (Optional) Install additional munin plugins '''''''''''''
You can find many plugins at munin-monitoring / contrib
- Just download raw files for plugins you need into /usr/share/munin/plugins
- Make them executable
- Symlink to /etc/munin/plugins/
- Add to /etc/munin/plugin-conf.d/munin-node
Here's an example for Nginx plugin:
cd /usr/share/munin/plugins
sudo wget -O nginx_request https://raw.github.com/munin-monitoring/contrib/master/plugins/nginx/nginx_request
sudo wget -O nginx_status https://raw.github.com/munin-monitoring/contrib/master/plugins/nginx/nginx_status
sudo wget -O nginx_memory https://raw.github.com/munin-monitoring/contrib/master/plugins/nginx/nginx_memory
sudo chmod +x nginx_*
sudo ln -s /usr/share/munin/plugins/nginx_* /etc/munin/plugins/
Edit /etc/munin/plugin-conf.d/munin-node and add the lines:
[nginx*]
env.url http://localhost/nginx_status
Restart munin-node:
sudo /etc/init.d/munin-node restart
More plugin installation examples
10. Reload http://stats.hostname.com/ in your browser and Enjoy! '''''''''''''
Now you should have all new plugins enabled.