19:19 Wednesday, November 11 2012

HOWTO: generate all Munin web content via cgi on Fedora

I've been using Munin for system monitoring, both at home and work, for a few years now. The monitoring portion works very well, and is great. The reporting portion has had problems for a long time. It simply didn't scale at all, because it used a cronjob to (re)generate all the HTML & image content for every system, every 5 minutes. That works ok if you have perhaps a dozen systems, but when you have hundreds, its a disaster. They started adding on-demand, perl/cgi based image generation support back in the 1.4.x days, but it was rather experimental, beta quality. It worked, but needed a ton of ugly hacks. Since munin-2.x was released, full perl/cgi on-demand content generation support was made a real feature. Unfortunately, the munin RPMs that ship with Fedora16+ have had numerous problems. I filed bug 861816 for this over a month ago, and its still not received any serious attention (unless you consider pushing out a fix that breaks it worse, a solution).

After repeated pleas for help on the munin mailing list, I finally broke through with the help of someone else on the list. What follows are all the steps needed to get full munin content generation with perl/cgi working in Fedora16 (and later). Hopefully the day will come when Fedora ships munin RPMs that take care of all of this out of the box.

First you need to install a few RPMs, create a directory, and fix permissions and ownership:
yum -y install mod_fcgid spawn-fcgi munin-cgi systemctl start munin-fcgi-graph.service munin-fcgi-html.service chgrp apache /var/log/httpd/munin/munin-cgi-* && chmod g+w /var/log/httpd/munin/munin-cgi-* mkdir -p /var/lib/munin/cgi-tmp/munin-cgi-graph && chown -R munin.apache /var/lib/munin/cgi-tmp && chmod -R u+g /var/lib/munin/cgi-tmp cp -R /var/www/cgi-bin/ /var/www/html/munin/cgi/

Set the following in munin.conf:
html_strategy cgi cgiurl_graph /cgi-bin/munin-cgi-graph

Put the following into the newly created /etc/httpd/conf.d/munin-cgi.conf :
Alias /static /etc/munin/static/ RewriteEngine on RewriteRule ^/cgi-bin/munin-cgi-html(\/.*?)*/static/(.*) /static/$2 [R,L] # Uncomment the following to redirect old, static URLs to the CGI-HTML RewriteRule ^/munin/(.*) /cgi-bin/munin-cgi-html/$1 [R,L] RewriteRule ^/cgi-bin/munin-cgi-html$ /cgi-bin/munin-cgi-html/ [R,L]

ScriptAlias /cgi-bin/munin-cgi-graph /var/www/cgi-bin/munin-cgi-graph
\
   Options +ExecCGI
   SetHandler fcgid-script
\

ScriptAlias /cgi-bin/munin-cgi-html /var/www/cgi-bin/munin-cgi-html
\
   Options +ExecCGI
   SetHandler fcgid-script
\

</code>

Restart apache:
systemctl restart httpd.service

You should see all your munin content generated on the fly: http://www.example.com/munin