wiki:MuninConfigurationMasterCGI-old

Munin graphing by CGI

Attention: Content of this page should be moved to the Munin-Guide --> Visit the Guide now.

CGI graphing is 1.4.x is more a proof of concept. It has been found severe bugs, and it really slow.
For real CGI, please use at least 2.0 beta 4, or better, the Debian Daily Packages?

If you use Munin 2.0 (or alpha or beta of 2.0) please see OutdatedMuninConfigurationMasterCGI.

CGI in Munin 2.0 has been enhanced a lot relative to this:

  1. Munin-graph is deprecated, and cgi is the only way to do graphing. This will more or less work out of the box, but it won't be using fast cgi, so it will not be as fast as it could be.
  2. Fastcgi is the vastly preferred way of doing CGI
  3. There is no longer a munin-fastcgi-graph program. munin-cgi-graph is fast-cgi capable (it autodetects this).
  4. It's mostly tested with apache(?)
  5. We will be writing new docs - before 2.0 is released at least

According to Jimmy who wrote this:

This is more a proof of concept than a recommended - it's slow. Also we do not test it before every release. There is a fastcgi version too which is explained at the end of this page. But you must do everything on this first check-list before you try that.

  1. munin-cgi-graph must be installed. This is included in the munin package in Debian and available in FreeBSD, too. On Debian, libdate-manip-perl is also required to graph by CGI (it is only recommeded by the munin package).
  2. munin-html must generate references to the cgi: In munin.conf set
    graph_strategy cgi
    
  3. The default relative URL for munin-cgi-graph is /cgi-bin/munin-cgi-graph this can be overridden in munin.conf with the cgiurl_graph keyword.
  4. Apache must be able to find and execute munin-cgi-graph at the given path - if it does not take a look at http://munin.projects.linpro.no/browser/trunk/resources/apache-cgi.conf.in
  5. Remove munin-graph from munin-cron (hum, this should be superflous, it should disable itself as needed)
  6. munin-cgi-graph should be able to write to the log file and graphics files. Assuming that your web server runs as the group 'www-data' and your file paths are the same as mine: (alternatively, you can make the CGI run as user "munin"!)
    chgrp www-data /usr/share/munin/munin-graph
    chgrp www-data /var/log/munin /var/log/munin/munin-graph.log
    chmod g+w /var/log/munin /var/log/munin/munin-graph.log
    
    chgrp -R www-data /var/www/munin/yourdomain
    chmod -R g+w /var/www/munin/yourdomain
    
  7. Depending on how log rotation for munin-graph.log is set up on your system, you may also need to modify group ownership and access permissions that a new log is created with upon rotation. (Otherwise the changes you made in the previous step would be reverted during the next logrotate.) On e.g. a Debian system, in /etc/logrotate.d/munin:
    # change this:
    /var/log/munin/munin-graph.log {
        daily
        missingok
        rotate 7
        compress
        notifempty
        create 640 munin adm      # !!!
    }
    # to this:
    /var/log/munin/munin-graph.log {
        # [...]
        create 660 munin www-data # !!!
    }
    

After all that and the next run of munin-html you've switched to cgi graphing. In case there are any problems you should watch your apache error log, and the munin-graph.log.

If you have munin 1.3.3 or later (r1217 is in 1.3.3, r1323 is in 1.3.4) you can tune how many concurent rrdgraph instances you allow. This can avoid I/O and memory thrashing effects and speed up the redraws when using cgi graphs. This is done in (/etc/munin/)munin.conf with the max_cgi_graph_jobs parameter.

FastCGI

The patches refered to below are (will be) in munin-fastcgi-graph in 1.4.0. The Apache configuration is still needed. And you need to do everything described above too.

  1. Install CGI::Fast, on Debian/Ubuntu? it's in libcgi-fast-perl.
  2. If you do not have 1.4: Apply the patch from #3.
  3. If you have 1.4: set cgiurl_graph so that the program name is "munin-fastcgi-graph"
  4. To make the Apache/mod_fastcgi handle the CGI program, add the SetHandler? directive to your "cgi-bin" directory, e.g.
    <Location /cgi-bin/munin-fastcgi-graph>
      SetHandler  fastcgi-script
    </Location>
    
  5. By default, mod_fastcgi uses dynamic servers, but you may want to setup a specific server (configuration) for this:
    <IfModule mod_fastcgi.c>
      FastCgiServer /usr/lib/cgi-bin/munin-fastcgi-graph -user munin -group munin
    </IfModule>
    
  6. Make sure munin-html has run once to change the URLs to use CGI graphs.
  7. Enjoy the speed improvement! :)

Configure lighttpd for munin-cgi-graph (fastcgi)

# munin fastcgi
server.modules += ( "mod_fastcgi" )
fastcgi.server = ("/cgi-bin/munin-cgi-graph" =>
                   ("munin" =>
                     ("socket" => "/var/run/lighttpd/munin-fastcgi-graph.sock",
                      "bin-path" => "/usr/lib/cgi-bin/munin-fastcgi-graph",
                      "check-local" => "disable",
                     )
                   )
                 )

Configure Nginx for munin-cgi-graph (fastcgi)

You need to spawn the munin-cgi-graph manually, you can use spawn-fcgi with the following options:

spawn-fcgi -s /var/run/munin/munin-fastcgi-graph.sock -U www-data -u munin -g munin munin-fastcgi-graph

on debian the files are called slightly different:

spawn-fcgi -s /var/run/munin/munin-fastcgi-graph.sock -U www-data -u munin -g munin /usr/lib/cgi-bin/munin-cgi-graph

munin-fast-cgi will run as munin user so there's no need to change permissions. Don't forget to write an init.d script to spawn munin-fast-cgi-graph on system startup, example: http://files.julienschmidt.com/public/cfg/munin/spawn-fcgi-munin-graph

        location ^~ /cgi-bin/munin-cgi-graph/ {
                fastcgi_split_path_info ^(/cgi-bin/munin-cgi-graph)(.*);
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_pass unix:/var/run/munin/munin-fastcgi-graph.sock;
                include fastcgi_params;
        }

debugging

there are logs in /var/log/munin-cgi-graph. if they are empty run the spawn-fcgi with -n to prevent forking and watch the errors.

HTML Generation by CGI

As of r4038, Munin contains capabilities for CGI generation of the HTML, too. As with the CGI graphing, this is good if you have relatively few views compared to updates. To enable CGI HTML, check that /usr/lib/cgi-bin/munin-cgi-html has been installed, then configure your webserver as below. Finally, you will probably want to remove or comment out (place a # at the start of the line) the following line in /usr/bin/munin-cron:

nice /usr/share/munin/munin-html $@ || exit 1

Apache

Add the following lines to /etc/munin/apache.conf

Alias /munin-static /etc/munin/static
<IfModule mod_rewrite.c>
    RewriteEngine on
    # 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]
    RewriteRule /cgi-bin/munin-cgi-html/static/(.*) /munin-static/$1 [R,L]
</IfModule>

Notes

  • After switching to "graph_strategy cgi" I had to manually create the directory "tld" in munins htdocs directory. I had moved it to another place, so the old structure was not there.
  • It was "quite adventurous" to set this all up in my Apache chroot.
  • You also want to apply the patch/fix from #480, if the image sizes are calculated incorrectly. This patch is in 1.4.0.

lighthttpd

TBD

Nginx

This config is based on a Munin 2.0 setup. I assume it works for 1.x too but it isn't tested yet! I highly recommend trying Munin 2.0 if you want to use FastCGI-Generation at all.

You need to spawn the munin-cgi-graph manually, you can use spawn-fcgi with the following options:

spawn-fcgi -s /var/run/munin-fastcgi-html.sock -U www-data -u munin -g munin munin-fastcgi-html

on debian the files are named slightly different:

spawn-fcgi -s /var/run/munin/munin-fastcgi-html.sock -U www-data -u munin -g munin /usr/lib/cgi-bin/munin-cgi-html

munin-fast-cgi will run as user munin so there is no need to change permissions. Do not forget to write an init.d script to spawn munin-fast-cgi-html on system startup. Example: http://files.julienschmidt.com/public/cfg/munin/spawn-fcgi-munin-html

Configure your Nginx-vhost:

    location /munin/static/ {
	alias /etc/munin/static/;
    }
    
    location /munin/ {
	fastcgi_split_path_info ^(/munin)(.*);
	fastcgi_param PATH_INFO $fastcgi_path_info;
	fastcgi_pass unix:/var/run/munin-fastcgi-html.sock;
	include fastcgi_params;
    }
Last modified at 2015-07-20T15:12:59+02:00 Last modified on 2015-07-20T15:12:59+02:00