Monitor nginx performance using netdata on centos
In this article
Yes, you can monitor nginx performance using Netdata on CentOS, and the setup is straightforward: install Netdata from its official repository, enable the nginx plugin, and point it at your nginx stub_status endpoint. Once configured, Netdata provides real-time, per-second dashboards for requests, connections, and response times without any custom scripting.
Why Netdata for nginx monitoring
Netdata is a real-time monitoring agent that collects thousands of metrics every second and presents them in an interactive web dashboard. Unlike traditional monitoring tools that poll every 30–60 seconds, Netdata's granular data helps you spot transient spikes in traffic or connection errors that would otherwise be invisible. For nginx, it gives you immediate visibility into request rates, active connections, and upstream response times—data that is critical for debugging slow pages or planning capacity.
On CentOS, Netdata installs as a systemd service and runs with minimal overhead (typically under 1% CPU on a modest VPS). It stores recent metrics in memory, so it doesn't consume disk space for long-term history, though you can configure it to archive to Prometheus or other backends.
Prerequisites and nginx stub_status
Netdata's nginx plugin reads the stub_status module output, which nginx exposes at a URL like http://127.0.0.1/nginx_status. This module is included in most nginx packages but is not enabled by default. You need to add a server block or location that enables it:
- Edit your nginx configuration (e.g.,
/etc/nginx/nginx.confor a site file in/etc/nginx/conf.d/). - Add a
locationblock that points to the stub_status module, typically inside aserverblock listening on localhost. - Restart nginx with
sudo systemctl restart nginx.
A typical configuration looks like:
server {
listen 127.0.0.1:80;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
After reloading, test with curl http://127.0.0.1/nginx_status—you should see lines starting with Active connections, server accepts, handled, and requests.
Installing Netdata on CentOS
Netdata provides an official installation script that works on CentOS 7 and 8 (and newer). The recommended method is:
- Run
bash <(curl -Ss https://my-netdata.io/kickstart.sh)as root. - The script detects your OS, installs dependencies, and sets up the Netdata service.
- After installation, the service starts automatically. Verify with
sudo systemctl status netdata.
Alternatively, you can use the yum package from Netdata's repository if you prefer manual control. The kickstart script is the most reliable for keeping the agent up to date.
Configuring the nginx plugin
Netdata's nginx plugin is disabled by default because it requires a valid URL. To enable it, edit the plugin configuration file at /etc/netdata/python.d/nginx.conf. The default file contains a commented example; you need to uncomment and set the url to your stub_status endpoint:
# /etc/netdata/python.d/nginx.conf localhost: name: 'local' url: 'http://127.0.0.1/nginx_status'
If your nginx uses HTTPS or a non-standard port, adjust the URL accordingly. After saving, restart Netdata: sudo systemctl restart netdata.
To verify the plugin is working, open the Netdata dashboard at http://your-server:19999 and look for the nginx section under the “Applications” or “Web server” category. You should see charts for requests per second, connections (active, reading, writing, waiting), and if you have the ngx_http_stub_status_module enabled, the accept and handled counters.
What metrics you get and how to read them
Netdata's nginx plugin provides several key charts:
- Requests per second – shows the rate of HTTP requests. A sudden spike may indicate a traffic surge or a DDoS attempt.
- Active connections – the number of connections currently being processed. High values relative to your worker_connections setting can cause 502 errors.
- Reading, Writing, Waiting – the current number of connections reading request headers, writing responses, and waiting for keep-alive. If “waiting” is consistently high, consider lowering keepalive_timeout.
- Accepts and handled – the total number of accepted and handled connections since nginx started. If handled is consistently lower than accepts, you may be dropping connections due to lack of worker connections.
Netdata also shows these in real time with per-second granularity, making it easy to correlate with CPU or memory spikes.
Common issues and troubleshooting
If the nginx section doesn't appear in the dashboard, check the following:
- stub_status not enabled – verify that
curl http://127.0.0.1/nginx_statusreturns the expected text. If not, your nginx may be missing the module or the location block is not active. - Firewall blocking access – Netdata runs on port 19999 by default. Ensure your firewall allows inbound connections to that port from your browser's IP.
- SELinux blocking – CentOS ships with SELinux enforcing. If Netdata cannot connect to the local nginx socket, run
sudo setsebool -P httpd_can_network_connect 1(or adjust the policy) to allow the connection. - Plugin disabled – check that the
nginx.conffile is not set toenabled: no.
Also, ensure that the Netdata user has permission to read the nginx status page—it's localhost, so it should, but if you have restrictive ACLs, you may need to adjust.
Costs and alternatives
Netdata is open-source and free to use, even for commercial purposes. The only cost is the server resources it consumes (minimal) and the time to configure it. If you need long-term historical data, you'll need to integrate with a time-series database like Prometheus, which adds complexity but is also free.
Alternatives include:
- nginx's own status module – gives raw counters but no visualization.
- Prometheus with nginx_exporter – more flexible for alerting, but requires setting up a full monitoring stack.
- Grafana with a data source – good for dashboards, but you still need a collector.
- Commercial tools like Datadog – easier but cost per host.
For a quick, zero-configuration solution on CentOS, Netdata is hard to beat.
Frequently Asked Questions
Does Netdata work with nginx in a Docker container on CentOS?
Yes, but you need to ensure the Netdata container can reach the nginx container's stub_status endpoint. Use a shared network or expose the status port. In the plugin config, set the URL to the container's IP or hostname.
How do I monitor multiple nginx servers with one Netdata instance?
Netdata is designed for per-host monitoring, so you'd install Netdata on each server. If you want a central view, you can use Netdata Cloud (free for up to a certain number of nodes) or stream metrics to a parent Netdata node.
Can I get alerts from Netdata for nginx issues?
Yes, Netdata includes a health monitoring engine. You can define alarms based on thresholds, such as requests per second or connection count, and receive notifications via email, Slack, or other channels.
Why is my nginx status page showing 404?
This usually means the stub_status module is not compiled into your nginx binary. On CentOS, the default nginx package includes it, but if you built nginx from source, you may need to recompile with --with-http_stub_status_module.
Does Netdata slow down nginx?
No. Netdata only reads the status page, which is a lightweight endpoint that nginx updates internally. The overhead is negligible.