说明:nginx没有使用模板来监控。自己写的脚本放到被监控的zabbix_agentd端
zabbix_agentd端的目录:/etc/zabbix/bin/
一 添加监控项:
vim nginx_status.sh
#!/bin/bash
HOST=`ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
PORT="80"
function active {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Active' | awk '{print $NF}' }
function reading {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Reading' | awk '{print $2}' }
function writing {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Writing' | awk '{print $4}' }
function waiting {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Waiting' | awk '{print $6}' }
function accepts {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $1}' }
function handled {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $2}' }
function requests {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $3}' }
# Run the requested function
$1
二 修改zabbix_agentd.conf配置文件,在最下面添加:
UserParameter=nginx.accepts,/etc/zabbix/bin/nginx_status.sh accepts
UserParameter=nginx.handled,/etc/zabbix/bin/nginx_status.sh handled
UserParameter=nginx.requests,/etc/zabbix/bin/nginx_status.sh requests
UserParameter=nginx.connections.active,/etc/zabbix/bin/nginx_status.sh active
UserParameter=nginx.connections.reading,/etc/zabbix/bin/nginx_status.sh reading
UserParameter=nginx.connections.writing,/etc/zabbix/bin/nginx_status.sh writing
UserParameter=nginx.connections.waiting,/etc/zabbix/bin/nginx_status.sh waiting
三 修改nginx配置文件 vim nginx.conf添加nginx_stataus状态页
location /nginx-status {
auth_basic "NginxStatus";
allow 192.168.43.0/24;
deny all;
stub_status on;
access_log on;
}
四 重启zabbix_agentd服务