一、开启nginx_status页面
server { \\定义一个虚拟主机 listen 80 default_server; \\定义监听地址 server_name _; \\定义主机名 location = /ngx_status { stub_status on; \\开启status access_log off; \\关闭访问日志 allow 127.0.0.1; \做访问权限控制 deny all; }
二、编写shell脚本获取ngx_status页面数据(文件路径为zabbix/script/nginx_status.sh)
#!/bin/bash Active(){ wget --quiet -O - http://127.0.0.1/ngx_status |awk ‘NR==1 {print$3}‘ } Accepts(){ wget --quiet -O - http://127.0.0.1/ngx_status |awk ‘NR==3 {print$1}‘ } Handled(){ wget --quiet -O - http://127.0.0.1/ngx_status |awk ‘NR==3 {print$2}‘ } Requests(){ wget --quiet -O - http://127.0.0.1/ngx_status |awk ‘NR==3 {print$3}‘ } Reading(){ wget --quiet -O - http://127.0.0.1/ngx_status |awk ‘NR==4 {print$2}‘ } Writing(){ wget --quiet -O - http://127.0.0.1/ngx_status |awk ‘NR==4 {print$4}‘ } Waiting(){ wget --quiet -O - http://127.0.0.1/ngx_status |awk ‘NR==4 {print$6}‘ } $1
三、定义zabbix获取数据时使用的key:(路径为:/opt/zabbix/etc/zabbix_agentd.conf.d/userparameter_nginx_status.conf)
UserParameter=nginx.accepts, /opt/zabbix/script/nginx_status.sh Accepts UserParameter=nginx.handled, /opt/zabbix/script/nginx_status.sh Handled UserParameter=nginx.requests, /opt/zabbix/script/nginx_status.sh Requests UserParameter=nginx.connections.active, /opt/zabbix/script/nginx_status.sh Active UserParameter=nginx.connections.reading, /opt/zabbix/script/nginx_status.sh Reading UserParameter=nginx.connections.writing, /opt/zabbix/script/nginx_status.sh Reading UserParameter=nginx.connections.waiting, /opt/zabbix/script/nginx_status.sh Waiting
四、重启zabbix_agetd服务
/etc/init.d/zabbix_agentd restart
五、利用zabbix_get检查,是否可以获取数据
zabbix_get -s 192.168.74.132 -p 10050 -k nginx.accepts 2194751016
六、制作模板
组态---->创建模板---->创建应用集------->创建项目(在项目中添加获取数据的key)---->创建图形
创建项目:
所有项目:
添加图形:
七、把制作好的模板应用到nginx主机,获取数据如下:
到此,zabbix监控nginx已经搭建完成
时间: 2024-12-24 21:57:13