tencent cloud


NGINX Exporter Integration

Last updated: 2024-01-29 15:55:08


    NGINX exposes certain monitoring metrics through the stub_status page. NGINX Prometheus Exporter collects the metrics of a single NGINX instance, converts them into monitoring data that can be used by Prometheus, and exposes the data to the Prometheus service for collection over the HTTP protocol. You can use the exporter to report the key monitoring metrics, which can be used for exception alerting and displayed on the dashboard.


    Using Docker container to run exporter

    Method 1. Use nginx-prometheus-exporter to quickly deploy the exporter in a Docker container. Run the following Docker command:
    $ docker run -p 9113:9113 nginx/nginx-prometheus-exporter:0.8.0 -nginx.scrape-uri http://<nginx>:8080/stub_status
    Method 2. Use the nginx-prometheus-exporter image to deploy the service in TKE and collect the monitoring data through TMP's self-discovery CRD PodMonitor or ServiceMonitor.

    Using binary program to run exporter

    Downloading and installing explorer

    1. Download NGINX Prometheus Exporter from the community for your runtime environment.
    2. Install NGINX Prometheus Exporter.

    Enabling NGINX stub_status feature

    1. The stub_status module of open-source NGINX provides a simple page to display the status data. Run the following command to check whether this module is enabled in NGINX:
    nginx -V 2>&1 | grep -o with-http_stub_status_module
    If with-http_stub_status_module is output on the terminal, the stub_status module in NGINX is enabled.
    If no result is output, you can use the --with-http_stub_status_module parameter to configure and compile NGINX again from the source code. Below is the sample code:
    ./configure \\
    sudo make install
    2. After confirming that the stub_status module is enabled, modify the NGINX configuration file to specify the URL of the stub_status page as follows:
    server {
    location /nginx_status {
    access_log off;
    deny all;
    3. Check NGINX and load it again to make the configuration take effect.
    nginx -t
    nginx -s reload
    4. After completing the above steps, you can view the NGINX metrics through the configured URL.
    Active connections: 45
    server accepts handled requests
    1056958 1156958 4491319
    Reading: 0 Writing: 25 Waiting : 7

    Running NGINX Prometheus Exporter

    Run the following command to start NGINX Prometheus Exporter:
    $ nginx-prometheus-exporter -nginx.scrape-uri http://<nginx>:8080/nginx_status

    Reported metrics

    nginxexporter_build_info, which is the exporter compilation information.
    All stub_status metrics.
    nginx_up, which displays the last scrape status. 1 indicates success, while 0 indicates failure.

    Configuring Prometheus scrape job

    1. After NGINX Prometheus Exporter runs normally, run the following command to add a job to the Prometheus scrape task.
    - job_name: 'nginx_exporter'
    - targets: ['your_exporter:port']
    2. Generally, the exporter and NGINX do not run together, so the instance of the reported data cannot describe the real instance. To facilitate data search and observation, you can modify the instance label and replace it with the real IP to make the label more intuitive as follows:
    - job_name: 'mysqld_exporter'
    - targets: ['your_exporter:port']
    - source_labels: [__address__]
    regex: '.*'
    target_label: instance
    replacement: ''

    Enabling database monitoring dashboard

    TMP provides a preconfigured NGINX exporter dashboard in Grafana. You can view the NGINX monitoring data in the following steps.
    1. Log in to the TMP console.
    2. Click
    on the right of the corresponding instance ID to view the data.
    Nginx Exporter dashboard
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support