zabbix 监控nginx状态
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix 监控nginx状态相关的知识,希望对你有一定的参考价值。
1.1 系统环境
centos6.6 zabbix2.28 nginx1.4+
1.2 配置nginx支持状态
#根据自己的环境配置
server { location /nginxstatus { stub_status on; access_log off; allow 172.16.10.0/24 ; deny all; }
#测试查看状态,出现结果,配置没问题
curl http://10.10.10.101/nginxstatus Active connections: 1 server accepts handled requests 1653507 1653507 1686937 Reading: 0 Writing: 1 Waiting: 0
1.3 配置zabbix客户端
[[email protected] ~]# cat /etc/zabbix/zabbix_agentd.d/nginx.conf UserParameter=nginx.status[*],/data/sh/zabbix_sh/zabbix_nginx.sh $1
1.4 脚本配置文件
[[email protected] ~]# cat /data/sh/zabbix_sh/zabbix_nginx.sh #!/bin/bash HOST=`ifconfig| grep -EA 2 "(eth1|em2)"| awk ‘/inet/{print $2}‘| cut -d: -f 2|head -1 ` PORT=80# echo $HOST #echo $PORT function ping { /sbin/pidof nginx | wc -l } # 检测nginx性能 function 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}‘} # 执行function $1
1.5 重启zabbix客户端
[[email protected] ~]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [确定] Starting Zabbix agent: [确定]
1.6 zabbix服务器端测试
zabbix_get -s 10.10.10.101 -k ‘nginx.status[active]‘ 1
1.7 导入模板,绑定模板
参照磁盘监控 http://bdstravel.blog.51cto.com/8870307/1758105
本文出自 “胡三刀” 博客,请务必保留此出处http://bdstravel.blog.51cto.com/8870307/1760451
以上是关于zabbix 监控nginx状态的主要内容,如果未能解决你的问题,请参考以下文章