munin + nginx: sin dynazoom en gráficos

munin + nginx: sin dynazoom en gráficos

No puedo hacer funcionar el zoom dinámico de Munin. Estoy bastante seguro de que el problema tiene algo que ver con la configuración de Nginx. Cualquier intento de generar un gráfico ampliado desencadena la siguiente entrada de error en el registro de nginx:

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"

Específicamente, sospecho que algo anda mal con los parámetros fastCGI. ¿Podría un alma buena y amiga echar un vistazo a mi servidor virtual Munin (ver más abajo) y explicarme qué pasa? Me está volviendo loco, pero tengo el presentimiento de que cualquier experto identificará el problema en una fracción de segundo...

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

   }

Respuesta1

¡Encontré esto mientras buscaba una solución a mi problema y buenas noticias! Resolví mi problema. Espero que esto también te ayude a que Munin trabaje en tu configuración.

Requisitos:

  • spawnfcgi:

    1. Clona o descarga el zip desde https://github.com/lighttpd/spawn-fcgi
    2. Prepararlo:
      autoreconf -v -i
    3. Compile e instale:
      ./configure && make && sudo make install

  • Scripts de inicio (no uso systemd, así que averigüe cómo crear un servicio):

    #! /bin/sh
    ### COMENZAR INFORMACIÓN INICIAL
    # Proporciona: munin-fastcgi
    # Inicio requerido: $remote_fs $network
    # Parada obligatoria: $remote_fs $network
    # Inicio predeterminado: 2 3 4 5
    # Detención predeterminada: 0 1 6
    # Breve descripción: inicia munin-fastcgi
    # Descripción: Generar sockets Munin FCGI para acceso web
    ### FIN INFORMACIÓN INICIAL
    
    #
    # munin-fastcgi Script de inicio para los servicios Munin CGI
    #
    #chkconfig: - 84 15
    # descripción: Cargando servicios Munin CGI usando spawn-cgi
    # Archivos HTML y CGI.
    #
    # Autor: Ryan Norbauer
    # Modificado: Geoffrey Grosenbach http://topfunky.com
    # Modificado: David Krmpotic http://davidhq.com
    # Modificado: Kun Xi http://kunxi.org
    # Modificado: http://drumcoder.co.uk/
    # Modificado: http://uname.pingveno.net/
    # Modificado: the_architecht http://iwbyt.com/
    RUTA=/usr/local/bin/:/usr/local/sbin:$RUTA
    DAEMON=$(que genera-fcgi)
    FCGI_GRAPH_SOCK=/var/run/munin/fastcgi-munin-graph.sock
    FCGI_HTML_SOCK=/var/run/munin/fastcgi-munin-html.sock
    WWW_USER=www-datos
    FCGI_USER=www-datos
    FCGI_GROUP=www-datos
    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 para gráficos y HTML"
    
    # Salir con gracia si el paquete ha sido eliminado.
    prueba -x $DAEMON || salir 0
    prueba -x $FCGI_SPAWN_GRAPH || salir 0
    prueba -x $FCGI_SPAWN_HTML || salir 0
    
    comenzar() {
      $DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH 2> /dev/null || echo "El gráfico ya se está ejecutando"
      $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 ya en ejecución"
    }
    
    detener() {
      matar -QUIT `gato $PIDFILE_GRAPH` || echo "El gráfico no se ejecuta"
      matar -QUIT `gato $PIDFILE_HTML` || echo "HTML no se está ejecutando"
    }
    
    Reanudar() {
      matar -HUP `gato $PIDFILE_GRAPH` || echo "No se puede recargar el gráfico"
      matar -HUP `gato $PIDFILE_HTML` || echo "No se puede recargar HTML"
    }
    
    caso "$1" en
      comenzar)
        echo "Iniciando $DESC: "
        comenzar
      ;;
      detener)
        echo "Deteniendo $DESC: "
        detener
      ;;
      reiniciar|recargar)
        echo "Reiniciando $DESC: "
        detener
        # Un segundo puede no ser tiempo suficiente para que un demonio se detenga,
        # si esto sucede, d_start fallará (y dpkg se romperá si
        # el paquete se está actualizando). Cambie el tiempo de espera si es necesario
        # be, o cambie d_stop para que start-stop-daemon use --retry.
        # Observe que el uso de --retry ralentiza un poco el proceso de apagado.
        dormir 1
        comenzar
      ;;
      *)
        echo "Uso: $SCRIPTNAME {inicio|detener|reiniciar|recargar}" >&2
        salida 3
      ;;
    esac
    
    salir $?
    

    Instale lo anterior /etc/init.d/munin-fcgicon permisos755

  • En su vhost, por ejemplo /etc/nginx/conf.d/example.com.conf, agregue esto en el server { }bloque. Puede cambiar los bloques de IP permitidos para que se ajusten a su configuración. Hice esto en un servidor local y quería que los gráficos munin estuvieran disponibles solo localmente.

    ubicación /munin {
    # alias /var/cache/munin/www;
        índice index.html;
    # incluir /etc/nginx/php.conf;
    # acceso_cerrar sesión;
        permitir 127.0.0.1;
        permitir 192.168.0.0/16;
        negar todo;                                
    }
    
    ubicación ^~ /munin-cgi/munin-cgi-graph/ {
    # if ($uri ~ /munin-cgi/munin-cgi-graph/([^/]*)) { set $ruta $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;
        incluir fastcgi_params;
    }
    ubicación ^~ /munin-cgi/munin-cgi-html/ {
    # if ($uri ~ /munin-cgi/munin-cgi-html/([^/]*)) { set $ruta $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;
        incluir fastcgi_params;
    }
    

  • Inicie /etc/init.d/munin-fcgi starty vuelva a cargar nginx y estará listo para comenzar.
  • PD: vinculé la carpeta html de munin a la carpeta de mi vhost: ln -s /var/cache/munin/www/ /var/www/example.com/munin -v.

    Respuesta2

    Esto suena como un problema con las definiciones en static/dynazoom.html. En nuestra instalación tenemos

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

    Sospecho que tienes

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

    Si bien debería ser

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

    Todavía estoy convencido de que aquí es donde reside el problema. La configuración de nginx parece correcta siempre que las solicitudes de gráficos ampliados comiencen con /cgi-bin/munin-cgi-graph. No veo de dónde /data/munin/...viene.

    Intente ejecutar en un entorno donde pueda monitorear las solicitudes enviadas por el navegador (fiddler, herramientas de desarrollo de Chrome) y ver qué se envía realmente.

    ¿Está seguro de que está editando la copia correcta de dynazoom? Intente realizar un cambio visible trivial solo para verificar esto.

    Respuesta3

    Tuve un problema similar en ubuntu 12.04 con munin 2.0.21.
    Compruebe dónde está intentando dynazoom encontrar munin-cgi-graph.
    La wiki de Munin diceque debes configurar tu nginx fcgi-graph para

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

    En mi caso, cuando examiné la página con la herramienta de desarrollo de Chrome (pestaña Red), encontré que dynazoom intentaba recuperar munin-cgi-graph de/munin-cgi/munin-cgi-graph/no de/cgi-bin/munin-cgi-graph/y obtiene error 404 en lugar de gráfico

    Entonces acabo de cambiar esta ubicación en la configuración de nginx:

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

    Parece que usted tiene el mismo problema: la ubicación de munin-cgi-graph es incorrecta, por lo que las solicitudes del navegador van root /data/munintal como indica el error.

    Respuesta4

    Algo que quería agregar a esta conversación. La información de the_architecht fue bastante valiosa, pero al menos a mí me faltaba algo.


    Usando CentOS 6.8 aquí:

    -

    1) Las rutas para los archivos CGI cambiaron, se pueden encontrar a través de localizar:

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

    Tuve que ir línea por línea en el script de inicio para comparar ubicaciones y dividir las líneas de inicio del demonio para ver qué estaba mal, lo que me permitió rastrear las diferencias en las rutas de los archivos.

    -

    2) Los permisos para los registros se establecieron para el usuario "munin", lo que provocó una especie de error silencioso. Para resolver esto agregué el usuario www-data al grupo munin y chmod 664 los archivos de registro:

    -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
    

    La entrega de permisos de archivos involucró elWiki Muninagregando -n al final del inicio del proceso spawn-fcgi y strace -s1024 que dio error

    write(2, "[jueves 27 de abril 21:47:35 2017] munin-cgi-html: No se puede abrir /var/log/munin/munin-cgi-html.log (permiso denegado) en /usr/share/ perl5/vendor_perl/Log/Log4perl/Appender/File.pm línea 103.\n", 180[jueves 27 de abril 21:47:35 2017] munin-cgi-html: No se puede abrir /var/log/munin/munin -cgi-html.log (Permiso denegado) en /usr/share/perl5/vendor_perl/Log/Log4perl/Appender/File.pm línea 103.


    Mi Nginx y spawn-fcgi finales están a continuación con mis modificaciones:

    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 $?
    

    información relacionada