8

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;
    }

   }
aag
  • 407
  • 1
  • 6
  • 17
  • The issue seems to be that the remote_user requests `/data/munin/usr/share/munin/cgi/munin-cgi-graph/... whereas the correct path should read: `usr/share/munin/cgi/munin-cgi-graph/...` The extra part `/data/munin/` is the root of the server (as specified in the root directive). How can I prevent the FastCGI process from adding the document root to the path? I tried deleting $document_root from the fastcgi_param but it did not help. – aag Feb 22 '15 at 21:14
  • 1
    I had the same problem sometime ago. I asked this http://serverfault.com/questions/615048/munin-dynamic-graph-zoom-dynazoom-not-working-nginx-php-fpm but no one knows how to fix it. – BigBob19202 Feb 22 '15 at 22:22

4 Answers4

2

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.

    0

    This sounds like a problem with the definitions in static/dynazoom.html. In our installation we have

    form.cgiurl_graph.value = qs.get("cgiurl_graph", "/munin-cgi/munin-cgi-graph");
    

    I suspect you have

    form.cgiurl_graph.value = qs.get("cgiurl_graph", "/usr/share/munin/cgi/munin-cgi-graph");
    

    Whilst it should be

    form.cgiurl_graph.value = qs.get("cgiurl_graph", "/cgi-bin/munin-cgi-graph");
    

    I'm still convinced this is roughly where the problem lies. The nginx config looks correct as long as requests for zoomed graphs start with /cgi-bin/munin-cgi-graph. I don't see where /data/munin/... is coming from.

    Try running in an environment where you can monitor the requests being sent by the browser (fiddler, chrome dev tools) and see what is really being sent.

    Are you sure you're editing the right copy of dynazoom? Try making a trivial visible change just to verify this.

    Paul Haldane
    • 4,457
    • 1
    • 20
    • 31
    • Thank you Paul. It is a good suggestion. Regrettably however my tweaks to dynazoom.html had no impact on the logged errors. I am still wondering whether I am doing something wrong with the setup of the nginx virtual munin server. – aag Mar 07 '15 at 20:43
    0

    I had similar problem on ubuntu 12.04 with munin 2.0.21.
    Check where dynazoom is trying to find munin-cgi-graph.
    Munin's wiki says that you should configure your nginx fcgi-graph for

    location ^~ /cgi-bin/munin-cgi-graph/
    

    In my case when i examine page with Chrome developer tool (Network tab) i found that dynazoom trying to fetch munin-cgi-graph from /munin-cgi/munin-cgi-graph/ not from /cgi-bin/munin-cgi-graph/ and it gets 404 erorr instead of graph

    So i just changed this location in nginx config:

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

    Looks like you have the same problem your munin-cgi-graph location is incorrect so browser requests go to root /data/munin just as error says.

    dima.butyrin
    • 146
    • 1
    • 8
    0

    Something I wanted to add to this conversation. The information from the_architecht was pretty invaluable, but something that was missing at least for me.


    Using CentOS 6.8 here:

    -

    1) Paths for the CGI files changed, those can be found via locate:

    /var/www/cgi-bin/munin-cgi-graph
    /var/www/cgi-bin/munin-cgi-html
    

    I had to go line by line in the start script to compare locations and break out the daemon start lines to see what was wrong which let me track down the file path differences.

    -

    2) Permissions for the logs were set to the "munin" user which caused a silent error of sorts. To solve this I added www-data user to the munin group and chmod 664 the log files:

    -rw-rw-r-- 1 munin munin 0 Apr 27 20:35 /var/log/munin/munin-cgi-graph.log
    -rw-rw-r-- 1 munin munin 0 Apr 27 20:35 /var/log/munin/munin-cgi-html.log
    

    The give away for the file permissions involved the Munin wiki adding the -n at the end of the spawn-fcgi process start and strace -s1024 which gave error

    write(2, "[Thu Apr 27 21:47:35 2017] munin-cgi-html: Can't open /var/log/munin/munin-cgi-html.log (Permission denied) at /usr/share/perl5/vendor_perl/Log/Log4perl/Appender/File.pm line 103.\n", 180[Thu Apr 27 21:47:35 2017] munin-cgi-html: Can't open /var/log/munin/munin-cgi-html.log (Permission denied) at /usr/share/perl5/vendor_perl/Log/Log4perl/Appender/File.pm line 103.


    My final Nginx and spawn-fcgi is below with my modifications:

    server {
    
            listen $IP;
            server_name $host.example.com;
    
                    access_log      /var/log/nginx/domlogs/munin-access.log;
                    error_log       /var/log/nginx/domlogs/munin-error.log;
    
        root /var/www/html/munin/;
        index   index.html;
    
    
    location / {
            auth_basic            "Restricted";
           # Create the htpasswd file with the htpasswd tool.
            auth_basic_user_file  /etc/nginx/htpasswd/munin;
    
    }
    
    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;
    }
    
    }
    

    #! /bin/bash
    ### 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/
    # Modified:     Jame Scott - NeCr0mStR
    
    DESC="Munin FCGI for Graph and HTML"
    
    SCRIPTNAME="$(tput setaf 1)Munin-FastCGI$(tput sgr0)"
    
    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=/var/www/cgi-bin/munin-cgi-graph
    FCGI_SPAWN_HTML=/var/www/cgi-bin/munin-cgi-html
    PIDFILE_GRAPH=/var/run/munin/fastcgi-munin-graph.pid
    PIDFILE_HTML=/var/run/munin/fastcgi-munin-html.pid
    
    # 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_graph() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}') ]];then
            local   RUNNING_PID_GRAPH=$(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}')
        fi
    
    
        if [[ -s ${PIDFILE_GRAPH} && ${RUNNING_PID_GRAPH} = $(cat ${PIDFILE_GRAPH}) ]];then
            echo -e "\nMunin-Graph already running"
        elif [[ -n ${RUNNING_PID_GRAPH} && ${RUNNING_PID_GRAPH} != $(cat ${PIDFILE_GRAPH}) && -S ${FCGI_GRAPH_SOCK} ]];then
            echo -e "\nMunin-Graph PID mismatch :: Cleaning up and starting Munin-Graph"
            kill -QUIT ${RUNNING_PID_GRAPH}
            sleep 1
                $DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH > /dev/null 2>&1
        else     
                $DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH > /dev/null 2>&1
                echo -e "Starting Munin-Graph\n"
        fi
    }
    
    start_html() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}') ]];then
            local   RUNNING_PID_HTML=$(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}')
        fi
    
    
        if [[ -s ${PIDFILE_HTML} && ${RUNNING_PID_HTML} = $(cat ${PIDFILE_HTML}) ]];then
            echo -e "\nMunin-HTML already running"
        elif [[ -n ${RUNNING_PID_HTML} && ${RUNNING_PID_HTML} != $(cat ${PIDFILE_HTML}) && -S ${FCGI_HTML_SOCK} ]];then
                echo -e "\nMunin-HTML PID mismatch :: Cleaning up and starting Munin-HTML"
                kill -QUIT ${RUNNING_PID_HTML}
                    sleep 1
                    $DAEMON -s $FCGI_HTML_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML > /dev/null 2>&1
        else       
                    $DAEMON -s $FCGI_HTML_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML > /dev/null 2>&1
                    echo -e "Starting Munin-HTML\n"
        fi
    }
    
    stop_graph() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}') ]];then
            local   RUNNING_PID_GRAPH=$(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}')
        fi
    
        if [[ -s ${PIDFILE_GRAPH} && $(cat ${PIDFILE_GRAPH}) = ${RUNNING_PID_GRAPH} ]];then
            kill -QUIT $(cat ${PIDFILE_GRAPH})
                echo -e "\nMunin-Graph stopped"
            elif [[ -z ${RUNNING_PID_GRAPH} && -s ${PIDFILE_GRAPH} ]];then
                    echo -e "\nGraph PID not found :: Cleaning up PID file"
                    rm ${PIDFILE_GRAPH}
            elif [[ -s ${PIDFILE_GRAPH} && $(cat ${PIDFILE_GRAPH}) != ${RUNNING_PID_GRAPH} ]];then
                    kill -QUIT ${RUNNING_PID_GRAPH}
                    rm ${PIDFILE_GRAPH}
                    echo -e "\nMunin-Graph stopped :: Cleaning up PID file"
        else 
                    echo -e "\nNo Munin-Graph process found"
        fi
    }
    
    stop_html() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}') ]];then
            local   RUNNING_PID_HTML=$(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}')
        fi
    
        if [[ -s ${PIDFILE_HTML} && $(cat ${PIDFILE_HTML}) = ${RUNNING_PID_HTML} ]];then
            kill -QUIT $(cat ${PIDFILE_HTML})
                echo -e "\nMunin-HTML stopped"
            elif [[ -z ${RUNNING_PID_HTML} && -s ${PIDFILE_HTML} ]];then
                echo -e "\nHTML PID not found :: Cleaning up PID file"
                    rm ${PIDFILE_HTML}
            elif [[ -s ${PIDFILE_HTML} && $(cat ${PIDFILE_HTML}) != ${RUNNING_PID_HTML} ]];then
                    kill -QUIT ${RUNNING_PID_HTML}
                    rm ${PIDFILE_HTML}
                    echo -e "\nMunin-HTML stopped :: Cleaning up PID file"
            else 
                    echo -e "\nNo Munin-HTML process found"
        fi
    }
    
    
    case "$1" in
        start)
            echo "Starting $DESC: "
            start_graph
            start_html
            ;;
        start_graph)
            echo "Starting Munin-Graph"
            start_graph
            ;;
        start_html)
            echo "Starting Munin-HTML"
            start_html
            ;;
        stop_graph)
            echo "Stopping Munin_Graph"
            stop_graph
            ;;
        stop_html)
            echo "Stopping Munin-HTML"
            stop_html
            ;;
        stop)
            echo "Stopping $DESC: "
            stop_graph
            stop_html
            ;; 
        restart|reload)
            echo "Restarting $DESC: "
            stop_html
            stop_graph
    
    # 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 5
            start_graph
            start_html
            ;;
        *)
            echo "$(tput setaf 2)Usage: $SCRIPTNAME $(tput setaf 7)$(tput setab 0){start_graph|start_html|stop_graph|stop_html|start|stop|restart|reload}$(tput sgr0) " >&2
            exit 3
            ;;
    esac
    
    exit $?