Guides - Capture NGINX Metrics with Longview
View real-time system metrics and resource utilization to gain insight into your Linux-based cloud workloads.
In addition to capturing general system metrics, Longview can also be used to capture metrics for NGINX. The NGINX tab appears in the Cloud Manager when Longview detects that you have NGINX installed on your system. It can help you keep track of NGINX workers, requests, system resource consumption, and other information.
In this Guide
This guide covers using Longview with NGINX and includes the following topics:
- Configuring Linode Longview for NGINX.
- Interacting with the NGINX data provided by Longview in the Cloud Manager.
- Troubleshooting Linode Longview for NGINX.
Configure Longview for NGINX
Automatic Configuration
These instructions are compatible only with Debian and Ubuntu and do not work on CentOS.
If NGINX is installed and running when you install the Longview agent, Longview should automatically configure itself for NGINX. If you install NGINX after setting up the Longview agent, you can perform the steps below to configure Longview with any available software integrations (Apache, NGINX, and MySQL). Any existing Longview data is not affected and will remain accessible.
SSH into the Compute Instance you are monitoring with Longview.
Ensure that NGINX is running.
sudo systemctl status NGINX
Run the automatic Longview configuration command.
dpkg-reconfigure -phigh linode-longview
For many systems, Longview should be able to configure itself automatically. If this is the case, your output should be similar to the following:
Checking Nginx configuration... Found nginx status page at http://127.0.0.2/nginx_status specified in /etc/linode/longview.d/Nginx.conf
If this output appears, Longview is configured and you can skip to the last step.
If Longview can’t locate the NGINX status page, a prompt may appear. This could indicate that the status page is in an unusual and unspecified location, or that the status module isn’t enabled, or that NGINX itself is misconfigured.
Select one of the options:
No: The configuration tool exits and you can perform a manual configuration. This may be safer if you have a delicate NGINX setup.
Yes: The configuration tool attempts to enable the status module, set the status page location in a new vhost configuration file, and restart NGINX. This option is easier, but has the potential to disrupt your current NGINX configuration. If you choose yes, and the configuration is successful, you should see output similar to the following:
[ ok ] Stopping Longview Agent: longview. Checking Nginx configuration... Restarting nginx: nginx. Finished configuring nginx, writing new configuration to /etc/linode/longview.d/Nginx.conf [ ok ] Starting Longview Agent: longview. update-rc.d: using dependency based boot sequencing
Note The automatic configuration sets the status page location tohttp://127.0.0.2/nginx_status
.
Refresh Longview in the Cloud Manager to verify that the NGINX tab is now present and collecting data for your Longview client instance.
If instead you received a failure message similar to the output example, double-check your NGINX installation and then perform a manual configuration. You can also visit the Troubleshooting section at the end of this guide.
[FAIL] Reloading web server config: nginx failed!
Manual Configuration
These instructions work for all supported distributions, including Debian, Ubuntu, and CentOS.
To enable the NGINX Longview integration manually, follow these steps on your system via SSH:
SSH into the Compute Instance you are monitoring with Longview.
Add the following lines to your NGINX configuration to enable the status module and set the location of the status page. The lines should be placed within your main configuration file’s
http
block (/etc/nginx/nginx.conf
) or in a separate site configuration file.- File: /etc/nginx/nginx.conf
1 2 3 4 5 6 7 8 9
server { listen 127.0.0.1:80; server_name 127.0.0.1; location /nginx_status { stub_status on; allow 127.0.0.1; deny all; } }
Restart NGINX:
sudo systemctl restart nginx
Edit the Longview configuration file for NGINX (
/etc/linode/longview.d/Nginx.conf
) so that it includes the following line. If this line is commented out, you can uncomment it.- File: /etc/linode/longview.d/Nginx.conf
1
location http://127.0.0.1/nginx_status
Restart Longview:
sudo systemctl restart longview
Refresh Longview in the Cloud Manager to verify that the NGINX tab is now present and collecting data for your Longview client instance.
You should now be able to see Longview data for NGINX. If that’s not the case, proceed to the Troubleshooting section at the end of this article.
View NGINX Metrics
Log in to the Cloud Manager and select the Longview link in the sidebar.
Locate the Longview Client you have configured for NGINX and click the corresponding View details link.
Select the NGINX tab.
You’ll see the current version of NGINX listed on the upper left-hand side of the page.
Mouse over a data point to see the exact numbers for that time. With Longview Pro, you can view older time periods for your data. The next sections cover the Longview Nginx App in detail.
Requests
The Requests graph shows the total number of requests NGINX handled at the selected time. This is every HTTP and HTTPS request to your system.
Connections
The Connections graph shows the amount of data that NGINX accepted and handled via web requests at the time selected.
Workers
The Workers graph shows all of the NGINX workers at the selected time. The workers are broken down by state:
- Waiting
- Reading
- Writing
CPU
The CPU graph shows the percentage of your system’s CPU being used by NGINX at the selected time. If you want to see the total CPU use instead, check the Overview tab.
RAM
The RAM graph shows the amount of RAM or memory being used by NGINX at the selected time. If you want to see your system’s total memory use instead, check the Overview tab.
Disk IO
The Disk IO graph shows the amount of input to and output from the disk caused by NGINX at the selected time. To see the total IO instead, visit the Disks tab.
Process Count
The Process Count graph shows the total number of processes on your system spawned by NGINX at the selected time. If you want to see more details, and how this stacks up against the total number of processes on your system, see the Processes tab.
Troubleshooting
If you don’t see Longview data for Nginx, you’ll instead get an error on the page and instructions on how to fix it. As a general tip, you can check the /var/log/linode/longview.log
file for errors as well.
Unable to Access Server Status Page for NGINX
The error will state Unable to access server status page (http://example.com/example) for Nginx: <error>
. This error occurs when NGINX’s status setting is disabled or has been changed from the default location.
location
listed in /etc/linode/longview.d/Nginx.conf
, or the default page at http://127.0.0.1/nginx_status
, but receives a non-200 HTTP response code. Basically, it means that the status page Longview is checking doesn’t exist.To fix this, follow these steps:
Make sure NGINX is running:
sudo systemctl restart nginx
Check the status page location, and make sure it’s available over Port 80. The default location Longview checks is
http://127.0.0.1/nginx_status
on localhost, but NGINX doesn’t typically have a status page location set up by default. In the NGINX configuration file (typically/etc/nginx/nginx.conf
) or in a separate site configuration file, this is designated with the lines in the example file below. If your configuration file does not contain these lines, add them to the file within thehttp
block. For more details, see the Manual Configuration section of this guide.- File: /etc/nginx/nginx.conf
1 2 3 4 5 6 7 8 9
server { listen 127.0.0.1:80; server_name 127.0.0.1; location /nginx_status { stub_status on; allow 127.0.0.1; deny all; } }
Longview is designed to check the default location automatically. If you use the default location shown above, you should be done. Refresh Longview in the Cloud Manager to verify that the NGINX tab is now present and collecting data for your Longview client instance.
If you’re not using the default location, you need to create a new file,
/etc/linode/longview.d/Nginx.conf
, and set thelocation
variable to match what you set in the NGINX configuration file:- File: /etc/linode/longview.d/Nginx.conf
1
location http://127.0.0.1/url-goes-here
Restart Longview:
sudo systemctl restart nginx
Refresh Longview in the Cloud Manager to verify that the NGINX tab is now present and collecting data for your Longview client instance.
--with-http_stub_status_module
and all your other settings. Then go back and try to enable the Longview Nginx App.The NGINX Status Page Doesn’t Look Right
The error will state The Nginx status page doesn't look right. Check <http://example.com/example> and investigate any redirects for misconfiguration.
This error occurs when Longview is able to reach the status page, but doesn’t receive the expected content.
To resolve this issue, follow these steps:
Visit the URL shown in the error. See if it directs or redirects you to a page that isn’t the NGINX status page.
Update your NGINX and Longview settings so that they specify the same status page location:
- The server_name and location lines in your NGINX configuration file. See the Manual Configuration section for more details.
- The location line in
/etc/linode/longview.d/Nginx.conf
If the location line isn’t set in
/etc/linode/longview.d/Nginx.conf
, Longview will check the default location ofhttp://127.0.0.1/nginx_status
on localhost.Make sure there aren’t any NGINX redirects or other settings that are affecting this page.
Restart Longview:
sudo systemctl restart longview
Refresh Longview in the Cloud Manager to verify that the NGINX tab is now present and collecting data for your Longview client instance.
NGINX Tab is Missing
If the Longview Nginx tab is missing entirely, this indicates that NGINX is either not installed, or has stopped. If you restart NGINX, you will be able to see the tab again and view all of your old data.
This page was originally published on