munin + nginx: no dynazoom into graphs

I cannot get the Munin dynamic zoom to work. I am rather certain that the problem has something to do with the Nginx configuration. Any attempt to generate a zoomed graph triggers the following error entry in the nginx log:

2015/02/22 13:26:01 [error] 4782#0: *2580 open() "/data/munin/usr/share/munin/cgi/munin-cgi-graph/bellaria/antergos1.bellaria/diskstats_latency/AntergosVG_AntergosRoot-pinpoint=1421756527,1424607727.png" failed (2: No such file or directory), client: 10.10.10.25, server: munin, request: "GET /usr/share/munin/cgi/munin-cgi-graph/bellaria/antergos1.bellaria/diskstats_latency/AntergosVG_AntergosRoot-pinpoint=1421756527,1424607727.png?&lower_limit=&upper_limit=&size_x=800&size_y=400 HTTP/1.1", host: "munin.bellaria", referrer: "http://munin.bellaria/static/dynazoom.html?cgiurl_graph=/usr/share/munin/cgi/munin-cgi-graph&plugin_name=bellaria/antergos1.bellaria/diskstats_latency/AntergosVG_AntergosRoot&size_x=800&size_y=400&start_epoch=1421756527&stop_epoch=1424607727"

Specifically, I suspect that something is wrong with the fastCGI parameters. May a good friendly soul take a look at my Munin virtual server (see below) and explain to me what's wrong? It's driving me crazy - yet I have a hunch that any expert will identify the problem in a fraction of a second...

# Munin server
server {
       listen 80;
    server_name munin munin.bellaria;
    root /data/munin;
    allow all;
    access_log logs/munin.access.log;
    error_log logs/munin.error.log;

    location / {
        index index.html index.htm index.php;
        }

    location ~ \.(php|html|html|cgi)$ {
        fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param   AUTH_USER $remote_user;
        fastcgi_param   REMOTE_USER $remote_user;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_index  index.php;
        include        fastcgi.conf;
        }


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

   }

Solution 1:

I found this while looking for a solution to my problem and good news! I solved my problem. I hope this will help you get munin working on your setup too.

Requirements:

  • spawnfcgi:
    1. Clone or download the zip from https://github.com/lighttpd/spawn-fcgi
    2. Prepare it:
      autoreconf -v -i
    3. Compile and install:
      ./configure && make && sudo make install

  • Init scripts (I don't do systemd so figure out how to make a service):
    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides:          munin-fastcgi
    # Required-Start:    $remote_fs $network
    # Required-Stop:     $remote_fs $network
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts munin-fastcgi
    # Description:       Spawn Munin FCGI sockets for Web access
    ### END INIT INFO
    
    #
    # munin-fastcgi     Startup script for Munin CGI services
    #
    # chkconfig: - 84 15
    # description: Loading Munin CGI services using spawn-cgi
    #              HTML files and CGI.
    #
    # Author:  Ryan Norbauer 
    # Modified:     Geoffrey Grosenbach http://topfunky.com
    # Modified:     David Krmpotic http://davidhq.com
    # Modified:     Kun Xi http://kunxi.org
    # Modified:     http://drumcoder.co.uk/
    # Modified:     http://uname.pingveno.net/
    # Modified:     the_architecht http://iwbyt.com/
    PATH=/usr/local/bin/:/usr/local/sbin:$PATH
    DAEMON=$(which spawn-fcgi)
    FCGI_GRAPH_SOCK=/var/run/munin/fastcgi-munin-graph.sock
    FCGI_HTML_SOCK=/var/run/munin/fastcgi-munin-html.sock
    WWW_USER=www-data
    FCGI_USER=www-data
    FCGI_GROUP=www-data
    FCGI_SPAWN_GRAPH=/usr/lib/munin/cgi/munin-cgi-graph
    FCGI_SPAWN_HTML=/usr/lib/munin/cgi/munin-cgi-html
    PIDFILE_GRAPH=/var/run/munin/fastcgi-munin-graph.pid
    PIDFILE_HTML=/var/run/munin/fastcgi-munin-html.pid
    DESC="Munin FCGI for Graph and HTML"
    
    # Gracefully exit if the package has been removed.
    test -x $DAEMON || exit 0
    test -x $FCGI_SPAWN_GRAPH || exit 0
    test -x $FCGI_SPAWN_HTML || exit 0
    
    start() {
      $DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH 2> /dev/null || echo "Graph Already running"
      $DAEMON -s $FCGI_HTML_SOCK  -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML 2> /dev/null || echo "HTML Already running"
    }
    
    stop() {
      kill -QUIT `cat $PIDFILE_GRAPH` || echo "Graph not running"
      kill -QUIT `cat $PIDFILE_HTML` || echo "HTML Not running"
    }
    
    restart() {
      kill -HUP `cat $PIDFILE_GRAPH` || echo "Can't reload Graph"
      kill -HUP `cat $PIDFILE_HTML` || echo "Can't reload HTML"
    }
    
    case "$1" in
      start)
        echo "Starting $DESC: "
        start
      ;;
      stop)
        echo "Stopping $DESC: "
        stop
      ;;
      restart|reload)
        echo "Restarting $DESC: "
        stop
        # One second might not be time enough for a daemon to stop,
        # if this happens, d_start will fail (and dpkg will break if
        # the package is being upgraded). Change the timeout if needed
        # be, or change d_stop to have start-stop-daemon use --retry.
        # Notice that using --retry slows down the shutdown process somewhat.
        sleep 1
        start
      ;;
      *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
        exit 3
      ;;
    esac
    
    exit $?
    

    Install the above under /etc/init.d/munin-fcgi with permissions 755

  • In your vhost, e.g. /etc/nginx/conf.d/example.com.conf, add this in the server { } block. You can change the ip blocks allowed to fit your setup. I did this on a local server and wanted the munin graphs to be available only locally.
    location /munin {
    #    alias /var/cache/munin/www;
        index index.html;
    #    include /etc/nginx/php.conf;
    #    access_log off;
        allow 127.0.0.1;
        allow 192.168.0.0/16;
        deny all;                                
    }
    
    location ^~ /munin-cgi/munin-cgi-graph/ {
    #   if ($uri ~ /munin-cgi/munin-cgi-graph/([^/]*)) { set $path $1; }
        fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/fastcgi-munin-graph.sock;
        include fastcgi_params;
    }
    location  ^~ /munin-cgi/munin-cgi-html/ {
    #   if ($uri ~ /munin-cgi/munin-cgi-html/([^/]*)) { set $path $1; }
        fastcgi_split_path_info ^(/munin-cgi/munin-cgi-html)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/fastcgi-munin-html.sock;
        include fastcgi_params;
    }
    

  • Start /etc/init.d/munin-fcgi start and reload nginx then you are good to go.
  • p.s I did link munin's html folder to my vhost's folder: ln -s /var/cache/munin/www/ /var/www/example.com/munin -v.