12

I would like to monitor NGinx stats through Munin but the Nginx plugins show no data. Is it possible to diagnose why only one of the munin nginx plugins seems to be working?

nginx munin

The server runs on CentOS 5.3

Glorfindel
  • 1,213
  • 3
  • 15
  • 22
Miko
  • 1,709
  • 4
  • 22
  • 28

6 Answers6

16

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.

Tom Feiner
  • 16,758
  • 8
  • 29
  • 24
  • 1
    Side note: Running Ubuntu 16.04 enabling nginx as documented here wasn't sufficient in my case. In addition I had to `apt install libwww-perl time` on munin nodes for its log stating issues with `Use of uninitialized value $LWP::VERSION` on nginx plugins. – Thomas Urban Aug 23 '17 at 03:32
  • Another side note: Since IPv6 is supported on servers today the default URL of nginx_* plugins using `http://localhost/` might prefer IPv6 and thus is going to mismatch the nginx configuration which is allowing IPv4 localhost, only. By fixing URL in `/etc/munin/plugin-conf.d/munin-node` to `http://127.0.0.1/nginx_status` eventually made the plugin working. – Thomas Urban Aug 23 '17 at 03:48
5

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
badew
  • 51
  • 1
  • 2
  • Based on the error messages in `/var/log/munin-update.log` (Service nginx_status on servername/127.0.0.1:4949 returned no data for label waiting), I could have searched for years to find out that `libwww-perl` was missing. Thanks a lot for this extensive answer. – BurninLeo Feb 19 '19 at 08:40
2

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?

CarpeNoctem
  • 2,397
  • 4
  • 23
  • 32
2

Key thing is the url in munin config.

You will need

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

Note

nginx_status

Not

nginx-status
Tien Do Xuan
  • 121
  • 3
0

Install libwww-perl then run the command munin-run nginx_status to see stats.
Restart muni-node service.

Thomas
  • 4,155
  • 5
  • 21
  • 28
0

If you need to set a different URL than http://localhost/nginx_status, make sure to add the plugin configuration to the correct file (munin.conf is the wrong one).

Best, create a new file /etc/munin/plugin-conf.d/nginx

[nginx*]
env.url http://localhost/status.pool1

Of course, the correct URL is defined in the PHP-FPM pool configuration (e.g., /etc/php/7.4/fpm/pool.d/www.conf) and access is granted in the webserver's configuration (see answers above).

Using sudo munin-run nginx_status may be helpful to search for additional errors.

BurninLeo
  • 860
  • 2
  • 11
  • 28