PDF

NGINX Monitoring via Telegraf in NetCrunch

Configure the Telegraf NGINX input plugin to collect web server metrics and send them to a NetCrunch Telemetry Node.

This document describes how to configure Telegraf to collect NGINX metrics and send them to NetCrunch through the Telemetry Node endpoint.


Overview

Telegraf can collect NGINX server metrics using the built-in NGINX input plugin. Data is forwarded to NetCrunch via HTTP POST to a Telemetry Node endpoint.


How NetCrunch Supports NGINX Telemetry

NetCrunch receives data from Telegraf through a Telemetry Node REST endpoint. Telemetry Nodes accept JSON-formatted data and store received values as counters or alert statuses.

Supported Endpoints

Cloud REST Endpoint:

https://gw.netcrunch.io/tm/v1/<serverId>@<sensorId>@<nodeId>/update

Local REST Endpoint:

<NetCrunch-WebServer>/api/rest/1/sensors/<sensorId>@<nodeId>/update

Example cloud endpoint:

https://gw.netcrunch.io/tm/v1/SRV-001@sensor01@node100/update

Data is sent via HTTP POST method with application/json content type. No IP discovery is required as the Telemetry Node exists logically in the NetCrunch structure.


Data Flow

NGINX monitoring via Telegraf follows this process:

  1. NGINX Status Exposure — NGINX exposes metrics through the stub_status module endpoint.

  2. Telegraf Collection — Telegraf NGINX input plugin queries the status endpoint at regular intervals.

  3. Data Forwarding — Telegraf forwards collected metrics to the NetCrunch Telemetry Node via HTTP POST.

  4. NetCrunch Processing — The Telemetry Node anchors incoming metrics and stores them as counters or alert statuses.


NGINX Configuration

Enable the stub_status module to expose metrics.

Configuration Example

Add to NGINX configuration file (e.g., /etc/nginx/nginx.conf or /etc/nginx/sites-available/default):

server { listen 127.0.0.1:80; server_name localhost;

location /nginx_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
}

}

Reload NGINX:

nginx -t systemctl reload nginx

Verify status endpoint:

curl http://127.0.0.1/nginx_status

Expected output:

Active connections: 45 server accepts handled requests 657 657 1126 Reading: 0 Writing: 36 Waiting: 9


Telegraf Configuration

The primary configuration file is /etc/telegraf/telegraf.conf.

Basic Configuration

[agent] interval = "30s" flush_interval = "30s" debug = false quiet = true

[[inputs.nginx]] urls = ["http://127.0.0.1/nginx_status"] response_timeout = "5s"

[[outputs.http]] url = "https://gw.netcrunch.io/tm/v1/SRV-001@sensor01@node100/update" method = "POST" data_format = "json" content_encoding = "identity" [outputs.http.headers] Content-Type = "application/json"

Configuration Parameters

Agent Section: - interval — Metric collection frequency - flush_interval — How often data is sent to outputs - debug — Enable detailed logging - quiet — Suppress non-error messages

NGINX Input: - urls — List of NGINX status endpoints to query - response_timeout — Maximum time to wait for response

HTTP Output: - url — NetCrunch Telemetry Node endpoint - method — HTTP method (POST) - data_format — Output format (JSON) - content_encoding — Encoding type - headers — HTTP headers including content type


Collected Metrics

The NGINX input plugin collects the following metrics:

Active Connections: - nginx_active — Number of active client connections

Server Metrics: - nginx_accepts — Total number of accepted client connections - nginx_handled — Total number of handled connections - nginx_requests — Total number of client requests

Connection States: - nginx_reading — Number of connections reading request headers - nginx_writing — Number of connections writing responses to clients - nginx_waiting — Number of idle connections waiting for requests


Advanced Configuration

Multiple NGINX Instances

Monitor multiple NGINX servers:

[[inputs.nginx]] urls = [ "http://server1.local/nginx_status", "http://server2.local/nginx_status", "http://server3.local/nginx_status" ] response_timeout = "5s"

Adding Custom Tags

Include additional metadata:

[[inputs.nginx]] urls = ["http://127.0.0.1/nginx_status"] response_timeout = "5s" [inputs.nginx.tags] environment = "production" datacenter = "dc01"

HTTPS Endpoints

For NGINX status over HTTPS:

[[inputs.nginx]] urls = ["https://server.local/nginx_status"] response_timeout = "5s" insecure_skip_verify = false # tls_ca = "/path/to/ca.crt"


Use Cases

Web Server Performance Monitoring

Track connection handling capacity and identify performance bottlenecks in high-traffic web servers.

Load Balancer Health Checks

Monitor NGINX instances acting as reverse proxies or load balancers to ensure proper request distribution.

Microservices Gateway Monitoring

Track metrics from NGINX API gateways handling microservices traffic.

Multi-Instance Monitoring

Collect metrics from multiple NGINX instances distributed across different servers or containers.


Summary

Telegraf provides straightforward integration with NGINX through the stub_status module. Metrics are collected at regular intervals and forwarded to NetCrunch Telemetry Nodes for centralized monitoring and alerting. This approach eliminates the need for SNMP configuration and provides real-time visibility into NGINX performance.

Key capabilities: - Real-time NGINX metrics collection - Support for multiple NGINX instances - Centralized monitoring through NetCrunch Telemetry Nodes - No polling required from NetCrunch server


See Also

Telegraf Integration with NetCrunch
Complete guide to using Telegraf with NetCrunch Telemetry Nodes.

Telemetry Node
Virtual node type designed for receiving external metrics and events via REST or OTLP.

Understanding NetCrunch Data Formats
Detailed explanation of JSON, XML, and CSV formats accepted by NetCrunch.

Sending Data to NetCrunch
Guide on using REST API, OTLP gateway, and file-based sensors to push data into NetCrunch.