Nginx Munin plugin shows no data

Solution 1:

The nginx plugins rely on the following URL to get the status info:

http://127.0.0.1/nginx_status

Usually, nginx does not have this URL configured to show status data.

From the documentation of the plugins, I see that nginx needs to be configured to show status data in a spesific URL.

You need to enable nginx status by adding the following lines to the site's configuration:

 server {
       listen 127.0.0.1;
       server_name localhost;
       location /nginx_status {
               stub_status on;
               access_log   off;
               allow 127.0.0.1;
               deny all;
       }
 }

Don't forget to restart the server after adding this configuration, and make sure the stus URL returns the status data.

For the complete documentation of each plugin, you can run:

munindoc nginx_request

Hope this helps.

Solution 2:

In my experience, these plugins are likely not working due to nginx misconfiguration. Here's a shortlist of what to do in this case:

1. Check nginx installation

Nginx must be compiled with HttpStubStatusModule module. You can check that by running following command (under sudo or root):

nginx -V 2>&1 | grep -o with-http_stub_status_module

If you see following output, you are good to go ahead.

with-http_stub_status_module

Otherwise, you have to re-compile nginx with the required module enabled or install from different source (In my case, the default Debian repo had the right version).

2. Check nginx configuration

I am assuming you have placed and enabled the required config. To see if it's working, you can ssh to your server and run

wget http://localhost/nginx_status

If you get no errors here, then the problem is plugin configuration. If server returns error here, you can debug by modifying configuration:

location /nginx_status {
    stub_status on;
    access_log   off;
    error_log    /var/log/nginx/status.error.log;
    allow 127.0.0.1;
    deny all;
}

After that, in the file /var/log/nginx/status.error.log you can see the exact reason why server returned an error:

[error] 2203#0: *1442 access forbidden by rule, client: ::1, server: localhost, request: "GET /nginx_status HTTP/1.1", host: "localhost"

In my case (as you can see from the log) the problem was client: ::1, while configuration only allowed access from 127.0.0.1

To resolve the issue, you can either follow cepharum's suggestion or modify virtual host configuration:

server {
        listen 80;
        listen [::]:80;
        server_name localhost;

        location /nginx_status {
                stub_status on;
                access_log off;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }
}

(Notice that I also replaced listen: 127.0.0.1 with port 80 (ipv4+ipv6) because the former also didn't work)

3. Check system config and dependencies

To check if plugin itself is working, run

munin-run nginx_status

(note that plugin must be "turned on" - a symlink must be present at /etc/munin/plugins - read the manual if not)

If you get errors with LWP library (e.g. LWP::UserAgent or LWP::VERSION), your system is missing a package required by nginx_status plugin.

On Debian / Ubuntu, run

apt install libwww-perl

On CentOS

yum install perl-libwww-perl

After that test the plugin again using munin-run. The expected output (numbers will be different):

total.value 1
reading.value 0
writing.value 1
waiting.value 0

Solution 3:

Possibly helpful:

cd /etc/munin/plugins
munin-run PLUGINNAME

Additionally use the debug option to munin-run.

Check the plugin file for any hard coded paths and verify they are correct for your system:

grep '/' PLUGINNAME

The nginx plugin may rely on Nginx being compiled with certain modules or log output in a certain format. Is there any documentation page for the plugins?


Solution 4:

Key thing is the url in munin config.

You will need

[nginx*]
env.url http://localhost/nginx_status

Note

nginx_status

Not

nginx-status

Tags:

Nginx

Munin