Zabbix_server 3.0.5
Zabbix_agentd 3.0.5
Zabbix_agentd端(被监控端)
Nignx在编译安装时需添加模块支持:--with-http_stub_status_module
Nginx的配置:
server{listen 80;server_name 127.0.0.1;location /nginxstatus {stub_status on;access_log off;allow 127.0.0.1;deny all;}}
#只允许本机获取nginxstatus信息
Zabbix_agentd配置:
vim /etc/zabbix/scritps/nginx_status.sh
#!/bin/bash# Set VariablesHOST="127.0.0.1"PORT="80"# Functions to return nginx statsfunction active {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Active' | awk '{print $NF}'}function reading {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Reading' | awk '{print $2}'}function writing {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Writing' | awk '{print $4}'}function waiting {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Waiting' | awk '{print $6}'}function accepts {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | awk NR==3 | awk '{print $1}'}function handled {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | awk NR==3 | awk '{print $2}'}function requests {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | awk NR==3 | awk '{print $3}'}# Run the requested function$1
chmod +x nginx_status.sh
vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx_status.conf
UserParameter=nginx.accepts,/etc/zabbix/scripts/nginx_status.sh acceptsUserParameter=nginx.handled,/etc/zabbix/scripts/nginx_status.sh handledUserParameter=nginx.requests,/etc/zabbix/scripts/nginx_status.sh requestsUserParameter=nginx.connections.active,/etc/zabbix/scripts/nginx_status.sh activeUserParameter=nginx.connections.reading,/etc/zabbix/scripts/nginx_status.sh readingUserParameter=nginx.connections.writing,/etc/zabbix/scripts/nginx_status.sh writingUserParameter=nginx.connections.waiting,/etc/zabbix/scripts/nginx_status.sh waiting
重启Zabbix_agentd
/etc/init.d/zabbix-agent restart
Zabbix_server端(监控端):
Zabbix_server端获取监控数据:
/usr/local/zabbix/bin/zabbix_get -s Zabbix_agentd端IP -p 10050 -k nginx.accepts
44365129
添加Nginx监控模板Template App Nginx Service.xml
3.0 2017-05-03T07:45:00Z Templates Template App Nginx Service Template App Nginx Service Templates Nginx Nginx Accepts 0 0 nginx.accepts 30 365 365 0 3 0 0 0 0 1 0 0 0 Nginx Nginx Connections Active 0 0 nginx.connections.active 30 365 365 0 3 0 0 0 0 1 0 0 0 Nginx Nginx Connections Reading 0 0 nginx.connections.reading 30 365 365 0 3 localhost 0 0 0 0 0 0 0 0 Nginx Nginx Connections Waiting 0 0 nginx.connections.waiting 30 365 365 0 3 localhost 0 0 0 0 0 0 0 0 Nginx Nginx Connections Writing 0 0 nginx.connections.writing 30 365 365 0 3 localhost 0 0 0 0 0 0 0 0 Nginx Nginx Handled 0 0 nginx.handled 30 365 365 0 3 localhost 0 0 0 0 0 0 0 0 Nginx Nginx Requests 0 0 nginx.requests 30 365 365 0 3 localhost 0 0 0 0 0 0 0 0 Nginx Nginx Clients Status 900 200 0.0000 100.0000 1 1 0 1 0 0.0000 0.0000 0 0 0 0 0 0 0000EE 0 2 0 Template App Nginx Service nginx.connections.active 1 0 EE0000 0 2 0 Template App Nginx Service nginx.connections.writing 2 0 EEEE00 0 2 0 Template App Nginx Service nginx.connections.waiting 3 0 00EE00 0 2 0 Template App Nginx Service nginx.connections.reading Nginx Socket Status 900 200 0.0000 100.0000 1 1 0 1 0 0.0000 0.0000 0 0 0 0 0 0 00EE00 0 2 0 Template App Nginx Service nginx.accepts 0 0 EE0000 0 2 0 Template App Nginx Service nginx.handled 1 0 EEEE00 0 2 0 Template App Nginx Service nginx.requests
关联对应的主机,根据需求设置修改相关的配置(Triggers Macros)