How to Enable and Monitor Nginx Stub_Status with Zabbix: Step-by-Step Guide
Learn how to verify the ngx_http_stub_status_module compilation, configure Nginx stub_status endpoint, create Bash monitoring scripts, set up Zabbix user parameters, and build templates, triggers, and graphs to monitor Nginx performance metrics such as active connections, requests, and waiting clients.
Detect Nginx Module
Nginx performance monitoring requires the ngx_http_stub_status_module to collect metrics.
1) Check whether the ngx_http_stub_status_module is compiled. /usr/local/nginx/sbin/nginx -V If the module is not enabled, recompile Nginx with the module (compilation steps omitted).
2) Add stub_status configuration to Nginx.
location /ngx_status {
stub_status on; # enable stub_status
allow 127.0.0.1; # only allow local access
access_log off; # disable logging (remove to enable)
deny all; # deny all other addresses
}3) Restart Nginx.
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload4) Access the stub_status endpoint. curl http://127.0.0.1/ngx_status Typical output includes:
Active connections: 1
server accepts handled requests
16214 16214 8269
Reading: 0 Writing: 1 Waiting: 0Parameter explanations: Active connections: current active client connections, including those waiting. accepts: total number of accepted client connections. handled: total number of connections handled by Nginx. requests: total number of client requests. Reading: number of connections where Nginx is reading request headers. Writing: number of connections where Nginx is writing a response. Waiting: number of idle connections waiting for a request.
Write Nginx Monitoring Script
1) Create the script file.
vim /usr/local/zabbix/scripts/ngx_status.sh #!/usr/bin/env bash
HOST='127.0.0.1'
PORT='80'
# Check if Nginx process is running (1 if running, 0 if stopped)
function ping {
/sbin/pidof nginx | wc -l
}
function active {
/bin/curl "http://${HOST}:${PORT}/ngx_status" -s >/dev/null | grep 'Active' | awk '{print $NF}'
}
function reading {
/bin/curl "http://${HOST}:${PORT}/ngx_status" -s >/dev/null | grep 'Reading' | awk '{print $2}'
}
function writing {
/bin/curl "http://${HOST}:${PORT}/ngx_status" -s >/dev/null | grep 'Writing' | awk '{print $4}'
}
function waiting {
/bin/curl "http://${HOST}:${PORT}/ngx_status" -s >/dev/null | grep 'Waiting' | awk '{print $6}'
}
function accepts {
/bin/curl "http://${HOST}:${PORT}/ngx_status" -s >/dev/null | awk NR==3 | awk '{print $1}'
}
function handled {
/bin/curl "http://${HOST}:${PORT}/ngx_status" -s >/dev/null | awk NR==3 | awk '{print $2}'
}
function requests {
/bin/curl "http://${HOST}:${PORT}/ngx_status" -s >/dev/null | awk NR==3 | awk '{print $3}'
}
$12) Set script permissions.
chown -Rf zabbix.zabbix /usr/local/zabbix/scripts/ngx_status.sh
chmod u+x /usr/local/zabbix/scripts/ngx_status.shZabbix GET Data Test
Run the following commands on the Zabbix server to test each metric:
zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[ping]" zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[active]" zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[reading]" zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[writing]" zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[waiting]" zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[accepts]" zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[handled]" zabbix_get -s 172.26.3.101 -p 10050 -k "ngx.status[requests]"Create Zabbix Template and Items
1) Create a new template in Zabbix (Configuration → Templates → Create template).
2) Create an application group within the template.
3) Add monitoring items (Configuration → Templates → Items → Create item).
4) Create triggers for process monitoring and for waiting connections > 100.
5) Create graphs to visualize the Nginx performance metrics.
Host Linked Template
Configure the host (Configuration → Hosts → select the host → Templates → Link template) and select the template created above.
View Data
Navigate to Monitoring → Latest data, select the host and the application group to see the collected metrics.
Use the graphs to visualize the data.
END
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
