Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input plugin nginx_plus_api http request throws "404 Not Found" error #5807

Closed
sushant-jaiswal opened this issue May 6, 2019 · 6 comments · Fixed by #6015
Closed

Input plugin nginx_plus_api http request throws "404 Not Found" error #5807

sushant-jaiswal opened this issue May 6, 2019 · 6 comments · Fixed by #6015
Labels
bug unexpected problem or unintended behavior
Milestone

Comments

@sushant-jaiswal
Copy link

Relevant telegraf.conf:

# Read Nginx Plus API advanced status information
[[inputs.nginx_plus_api]]
  ## An array of Nginx API URIs to gather stats.
  urls = ["http://127.0.0.1/api"]
  # Nginx API version, default: 3
  api_version = 4

System info:

Ubuntu Xenial (16.04)
Nginx Plus R18
Telegraf 1.10.2

Steps to reproduce:

  1. Added following block to enable ngx_http_api_module in /etc/nginx/nginx.conf-
    server {
        listen 127.0.0.1;

        location /api {
            api write=on;
            allow 127.0.0.1;
            deny all;
        }
    }
  1. Changed telegraf.conf as mentioned in the beginning, to add input plugin nginx_plus_api.
  2. Restarted telegraf
  3. Check Telegraf log

Expected behavior:

Ngnix metrics data through the API

Actual behavior:

Getting following error-

2019-05-06T10:06:19Z E! [inputs.nginx_plus_api]: Error in plugin: http://127.0.0.1/api returned HTTP status 404 Not Found

Additional info:

Checked gatherUrl function in file "nginx_plus_api_metrics.go". Just to see some more error details, changed the urls value in "telegraf.conf" to 127.0.0. (removed 1 from last). Restarted Telegraf and got the error as below-

2019-05-06T10:07:54Z E! [inputs.nginx_plus_api]: Error in plugin: error making HTTP request to http://127.0.0./api: Get http://127.0.0./api/4/processes: dial tcp: lookup 127.0.0.: no such host

When opening the correct URL http://127.0.0.1/api/4/processes from the machine, it is accessible and response is Successful.

Not sure why should we get "HTTP status 404 Not Found" as mentioned in Actual Behavior. The URLs seem to be good, then why it should go the block if resp.StatusCode != http.StatusOK {. It brings my doubt on resp, err := n.client.Get(url), which is very unlikely to be an issue.

We want to start using this plugin, so any help is appreciated. Thanks.

@danielnelson danielnelson added the bug unexpected problem or unintended behavior label May 6, 2019
@danielnelson danielnelson self-assigned this May 6, 2019
@danielnelson
Copy link
Contributor

Could you run it again with this build of #5811. This should correct the error message so we can see the actual path returning 404, currently it is just showing the URL from the config file.

@sjaiswalvmware
Copy link

Thanks @danielnelson for quick response.
I tried this build #5811 and now it shows URL in the error, which is actually throwing 404. That is expected, as we do not have "stream" folder for any of 4 APIs, so these URLs are not accessible from my browsers as well. Here is the error-

2019-05-07T04:33:30Z E! [inputs.nginx_plus_api]: Error in plugin: http://127.0.0.1/api/4/stream/server_zones returned HTTP status 404 Not Found
2019-05-07T04:33:30Z E! [inputs.nginx_plus_api]: Error in plugin: http://127.0.0.1/api/4/stream/upstreams returned HTTP status 404 Not Found

@danielnelson
Copy link
Contributor

It doesn't look like this should interrupt any other metrics, are other metrics being collected? If so you can ignore this error until we fix the logging. I think we just need to make the 404 error ignored in the plugin for these endpoints.

@sushant-jaiswal
Copy link
Author

We are only getting metrics mentioned below. Other metrics are not getting collected. Not sure if they all are due to the 404 errors or there are other issues.

nginx_plus_api_processes
nginx_plus_api_connections
nginx_plus_api_ssl
nginx_plus_api_http_requests

@sushant-jaiswal
Copy link
Author

I guess I need to enable the NGINX load balancers to get other missing metrics. I will have to try that and see if they get collected. If yes, then probably, we just have issues with stream/server_zones and stream/upstreams.

@sushant-jaiswal
Copy link
Author

@danielnelson After configuring the load balancer, we are getting all metrics. So, there does not seem to be any issue with metrics collection. As you said, looks like only logging needs to be taken care then.

goller added a commit that referenced this issue Jun 19, 2019
Closes #5807

Currently, this plugin tries a set of hardcoded paths.  Not all paths are enabled in a standard NGINX configuration.
This PR skips any API resource paths that do not exist.

However, the correct way would be to get the paths from NGINX itself at /api, /api/4, etc rather than have a set
of hardcoded paths.
@danielnelson danielnelson added this to the 1.11.1 milestone Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants