目录
1.修改客户端Nginx皮配置文件
[root@khd ~]# vim /usr/local/Nginx/conf/Nginx.conf
......
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /status {
stub_status on;
allow all;
}
#error_page 404 /404.html;
.....
2.修改客户端zabbix的配置文件
[root@khd ~]# vim /usr/local/etc/zabbix_agentd.conf
······
# Range: 0-1
# Default:
UnsafeUserParameters=1
UserParameter=Nginx_status[*],/bin/bash /usr/local/etc/zabbix_agentd.conf.d/Nginx_monitor.sh $1 //bash后面跟上脚本的绝对路径,$1代表参数
### Option: UserParameter
········
重启一下zabbix
[root@khd ~]# pkill zabbix
[root@khd ~]# zabbix_agentd
@H_404_32@3.写zabbix的监控脚本
[root@khd ~]# cd /usr/local/etc/zabbix_agentd.conf.d/
[root@khd zabbix_agentd.conf.d]# vim Nginx_monitor.sh
Nginx_PORT=80
Nginx_COMMAND=$1
Nginx_active(){
/usr/bin/curl -s "http://127.0.0.1:"$Nginx_PORT"/status/" |awk '/Active/ {print $NF}'
}
Nginx_reading(){
/usr/bin/curl -s "http://127.0.0.1:"$Nginx_PORT"/status/" |awk '/Reading/ {print $2}'
}
Nginx_writing(){
/usr/bin/curl -s "http://127.0.0.1:"$Nginx_PORT"/status/" |awk '/Writing/ {print $4}'
}
Nginx_waiting(){
/usr/bin/curl -s "http://127.0.0.1:"$Nginx_PORT"/status/" |awk '/Waiting/ {print $6}'
}
Nginx_accepts(){
/usr/bin/curl -s "http://127.0.0.1:"$Nginx_PORT"/status/" |awk 'NR==3 {print $1}'
}
Nginx_handled(){
/usr/bin/curl -s "http://127.0.0.1:"$Nginx_PORT"/status/" |awk 'NR==3 {print $2}'
}
Nginx_requests(){
/usr/bin/curl -s "http://127.0.0.1:"$Nginx_PORT"/status/" |awk 'NR==3 {print $3}'
}
case $Nginx_COMMAND in
active)
Nginx_active;
;;
reading)
Nginx_reading;
;;
writing)
Nginx_writing;
;;
waiting)
Nginx_waiting;
;;
accepts)
Nginx_accepts;
;;
handled)
Nginx_handled;
;;
requests)
Nginx_requests;
;;
*)
echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
esac
给脚本加执行权限
[root@khd zabbix_agentd.conf.d]# chmod +x Nginx_monitor.sh
4.在服务端测试键值能否使用
[root@fwd ~]# zabbix_get -s 192.168.153.173 -k Nginx_status[waiting]
4.1 添加监控项和触发器
4.2验证
多开几个网页,触发监控
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。