NGINX Plus Live Activity Monitoring in 3 Simple Steps

Original: https://www.nginx.com/blog/live-activity-monitoring-nginx-plus-3-simple-steps/

One of the most popular features in NGINX Plus is live activity monitoring, also known as extended status reporting. The live activity monitor reports real‑time statistics for your NGINX Plus installation, which is essential for troubleshooting, error reporting, monitoring new installations and updates to a production environment, and cache management.

We often get questions from DevOps engineers – experienced and new to NGINX Plus alike – about the best way to configure live activity monitoring. In this post, we’ll describe a sample configuration file that will have you viewing real‑time statistics on the NGINX Plus dashboard in just a few minutes.

The sample configuration file for live activity monitoring makes it even easier to set up many of NGINX Plus’ advanced features in your environment. The set of examples will grow over time, and the NGINX Plus packages available at the NGINX Plus repository will include the latest versions available when the packages are created.

Here we’ll review the instructions for installing and customizing the file.

Note: These instructions assume that you use the conventional NGINX Plus configuration scheme (in which configuration files are stored in the /etc/nginx/conf.d directory), which is set up automatically when you install an NGINX Plus package. If you use a different scheme, adjust the commands accordingly.

Installing the Configuration File

The commands do not include prompts or other extraneous characters, so you can cut and paste them directly into your terminal window.

  1. Download the sample configuration file.

    cd /etc/nginx/conf.d/
    curl https://www.nginx.com/resource/conf/status.conf > status.conf
  2. Customize your configuration files as instructed in Customizing the Configuration.

  3. Test the configuration file for syntactic validity and reload NGINX Plus.

    nginx -t && nginx -s reload

The NGINX Plus dashboard is available immediately at http://nginx-server-address:8080/ (or the alternate port number you configure as described in Changing the Port for the Dashboard).

Customizing the Configuration

To get the most out of live activity monitoring, make the changes described in this section to both the sample configuration file and your existing configuration files.

Monitoring Servers and Upstream Server Groups

For statistics about virtual servers and upstream groups to appear on the dashboard, you must enable a shared memory zone in the configuration block for each server and group. The shared memory is used to store configuration and run‑time state information referenced by the NGINX Plus worker processes.

If you don’t configure shared memory, the dashboard reports only basic information about the number of connections and requests, plus caching statistics. In the live demonstration dashboard, this corresponds to the first line (to the right of the NGINX+ logo) and the final Caches section.

Edit your existing configuration files to add the status_zone directive to the server configuration block for each server you want to appear on the dashboard. (You can specify the same zone name in multiple server blocks, in which case the statistics for those servers are aggregated together in the dashboard.)

server {
    listen 80;
    status_zone backend-servers;
    location / {
        proxy_pass http://backend;
    }
}

Similarly, you must add the zone directive to the upstream configuration block for each upstream group you want to appear on the dashboard. The following example allocates 64 KB of shared memory for the two servers in the upstream‑backend group. The zone name for each upstream group must be unique.

upstream backend {
    zone upstream-backend 64k;
    server 10.2.3.5;
    server 10.2.3.6;
}

Restricting Access to the Dashboard

The default settings in the sample configuration file allow anyone on any network to access the dashboard. We strongly recommend that you configure at least one of the following security measures:

Changing the Port for the Dashboard

To set the port number for the dashboard to a value other than 8080, edit the following listen directive in the sample configuration file.

listen 8080;

Limiting the Monitored IP Addresses

If your NGINX Plus server has several IP addresses and you want the dashboard to display statistics for only some of them, create a listen directive for each one that specifies its address and port. The sample configuration script includes the following example that you can uncomment and change to set the correct IP address. You also need to comment out the listen directive (with a port number only) discussed in Changing the Port for the Dashboard.

listen 10.2.3.4:8080;

NGINX Plus Dashboard Demo

To view a demo of the NGINX Plus live activity monitoring dashboard, click here.

More Information about Live Activity Monitoring

To try NGINX Plus, start your free 30-day trial today or contact us for a demo.

Retrieved by Nick Shadrin from nginx.com website.