All Products
Search
Document Center

:Monitor an NGINX cluster

Last Updated:Dec 30, 2024

Alibaba Cloud Managed Service for Prometheus offers seamless integration with NGINX components, enabling the collection of vital metrics such as incoming requests, bytes transferred, and response times. By integrating NGINX components with Managed Service for Prometheus, you can leverage out-of-the-box dashboards to monitor performance, optimize server configurations, and troubleshoot issues as needed. This topic describes how to monitor an NGINX cluster.

Background information

You can view the metrics collected from an NGINX cluster on the Integration Center page in the ARMS console. 9.jpg

Prerequisites

  • NGINX has been installed and can run as expected.

  • To enable the monitoring of the NGINX stub status module, install ngx_http_stub_status_module.

    Procedure for installing ngx_http_stub_status_module

    1. Check whether ngx_http_stub_status_module is installed.

      nginx -V 2>&1 | grep -o with-http_stub_status_module
      • A similar output indicates that ngx_http_stub_status_module is installed.cw_prom_exporter_nginx_module

      • If ngx_http_stub_status_module is not installed, run the following commands to install the module:

        wget http://nginx.org/download/nginx-1.13.12.tar.gz
        tar xfz nginx-1.13.12.tar.gz
        cd nginx-1.13.12/
        ./configure --with-http_stub_status_module
        make
        make install
    2. Start ngx_http_stub_status_module to query the NGINX status.

      location /nginx_status {
        stub_status on;
        allow 127.0.0.1;  #only allow requests from localhost
        deny all;   #deny all other hosts 
       }
      Note
      • The value of location must be nginx_status.

      • allow 127.0.0.1 and deny all allow only local access. To allow access from the NGINX cluster, comment out these two lines of code, or change 127.0.0.1 to the IP address of the NGINX cluster.

    3. Restart NGINX.

      nginx -t
      nginx -s reload 
    4. (Optional) Check whether ngx_http_stub_status_module is started.

      curl http://127.0.0.1/nginx_status

      A similar output indicates that ngx_http_stub_status_module is started.

      wo

  • To enable the monitoring of the NGINX virtual host traffic status (VTS) module, install nginx-module-vts.

    Procedure for installing nginx-module-vts

    1. Download nginx-module-vts at https://github.com/vozlt/nginx-module-vts.

    2. Compile the NGINX configuration file.

      1. Add nginx-module-vts to the NGINX configuration file.

        --add-module=/path/to/nginx-module-vts
      2. Download the official software package and compile it into nginx-module-vts.

        ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_sysguard_module  --add-module=nginx-module-vts
    3. Install nginx-module-vts.

      make && make install
    4. Modify the NGINX configuration file and add a monitoring interface.

      http {
          vhost_traffic_status_zone;
              vhost_traffic_status_filter_by_host on;
      
          ...
      
          server {
      
              ...
      
              location /status {
                  vhost_traffic_status_display;
                  vhost_traffic_status_display_format html;
              }
          }
      }

      We recommend that you run the following command to enable vhost filtering:

      vhost_traffic_status_filter_by_host on
      Note

      If you configure multiple server names in NGINX, you can enable vhost filtering to ensure that the system collects traffic data based on different server names. If you do not enable vhost filtering, the system attributes all traffic to the first server.

      If you do not need to monitor traffic by region, you can run the following commands to disable vhost filtering, where the ellipses (...) indicate omitted code:

      server {
      ...
      vhost_traffic_status off;
      ...
      }
    5. Check whether nginx-module-vts is installed.

      curl http://127.0.0.1/status

Procedure

  1. Log on to the ARMS console.

  2. In the left-side navigation pane, click Integration Center. On the page that appears, click the Nginx card.

  3. On the Nginx page, set parameters.

    1. Select the environment type.

      • Kubernetes Environment: The monitored object runs in a Container Service for Kubernetes (ACK) cluster.

      • ECS(VPC): The monitored object runs on an Elastic Compute Service (ECS) instance.

    2. Select an ACK cluster or an ECS instance as prompted.

    3. Set the Configuration Information section.

      ACK cluster

      Parameter

      Description

      Example

      Name(Not required)

      The name of the NGINX cluster that you want to integrate into Managed Service for Prometheus.

      nginxtest123

      Enable Nginx for Stub Status monitoring

      Specifies whether to use ngx_http_stub_status_module (a built-in module in NGINX) to collect metrics, including the number of requests received and processed by NGINX.

      Note

      Before enabling this monitoring feature, ensure that ngx_http_stub_status_module is installed. For more information, see ngx_http_stub_status_module.

      N/A

      Enable Nginx for Vts monitoring

      Specifies whether to use nginx-module-vts to collect metrics, including the number of NGINX requests, number of bytes, and response time.

      Note

      Before enabling this monitoring feature, ensure that nginx-module-vts is installed. For more information, see nginx-module-vts.

      N/A

      Nginx Host

      The domain name of the NGINX service.

      The following domain names are supported:

      • Endpoint of the NGINX service within the cluster

      • Internal IP address of the ACK cluster where the NGINX service resides

      • Public IPv4 address of the NGINX service

      nginx-server.namespace

      Nginx Port

      The port number of the NGINX server.

      80

      Metric collection interval(Unit/second)

      The interval for collecting monitoring data. Default value: 15. Unit: seconds.

      15

      ECS (VPC)

      Parameter

      Description

      Example

      Name(Not required)

      The name of the NGINX cluster that you want to integrate into Managed Service for Prometheus.

      nginxtest321

      Enable Nginx for Stub Status monitoring

      Specifies whether to use ngx_http_stub_status_module (a built-in module in NGINX) to collect metrics, including the number of requests received and processed by the NGINX service.

      N/A

      Enable Nginx for Vts monitoring

      Specifies whether to use nginx-module-vts to collect metrics, including the number of NGINX requests, number of bytes, and response time.

      Note

      Before enabling this monitoring feature, ensure that nginx-module-vts is installed. For more information, see nginx-module-vts.

      N/A

      Nginx Host

      The domain name of the NGINX service.

      The following domain names are supported:

      • Endpoint of the NGINX service within the cluster

      • Internal IP address of the ACK cluster where the NGINX service resides

      • Public IPv4 address of the NGINX service

      nginx-server.namespace

      Nginx Port

      The port number of the NGINX server.

      80

      Metric collection interval(Unit/second)

      The interval for collecting monitoring data. Default value: 15. Unit: seconds.

      15

      Custom Labels

      The custom tags of metrics of the ECS instance deployed in a virtual private cloud (VPC) that you want to monitor.

      By configuring tags, you can organize, query, monitor, or analyze the metrics in a fine-grained manner when you use tools such as Grafana. For more information, see Add tags to the metrics of an ECS instance using a VPC.

      Note
      • A tag key cannot contain special characters, such as hyphens (-), periods (.), and percent signs (%). The special characters are used in the Prometheus functionality.

      • Tags are in a key-value data format.

      test1:aaa

View monitoring information

To view integrated components, you can click Integration Management in the left-side navigation pane. After you click the component card, you can view information such as targets, metrics, dashboards, alerts, service discovery configurations, and components in the panel that appears.image