环境:
zabbix 2.0
Zabbix Server: 172.28.2.119
Zabbix nginx 客户端: 172.28.2.151
前提是nignx在编译安装时加上:--with-http_stub_status_module -----这个大家都知道!!
同时还要在nginx的配置文件中加上:
- location /status
- {
- stub_status on;
- access_lod off;
- allow 127.0.0.1;
- allow 172.28.2.119; #这是我们zabbix监控服务器IP
- }
下面说下zabbix对nginx的监控原理:
Zabbix Server <---(Zabbix Agent)---> nginx客户端key(要写入客户端配置文件中) <--- 脚本 --->nginx状态参数
nginx web界面nginx状态显示情况如下图:

1.创建获取nginx的status参数数据传送到server端脚本
- [root@Zabbix_Server script]# cat >> /usr/local/sbin/nginx_status.sh << EOF
- #!/bin/bash
- # Script to fetch nginx statuses for tribily monitoring systems
- # License: GPLv4
- # Set Variables
- BKUP_DATE=`/bin/date +%Y%m%d`
- LOG="/etc/zabbix/nginx_status.log"
- #HOST=`/sbin/ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
- HOST=`/sbin/ifconfig eth0 |grep "inet addr" |awk -F[:" "] '{print $13}'`
- PORT="80"
- # Functions to return nginx stats
- function active {
- /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Active' | awk '{print $NF}'
- }
- function reading {
- /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Reading' | awk '{print $2}'
- }
- function writing {
- /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Writing' | awk '{print $4}'
- }
- function waiting {
- /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
- }
- function accepts {
- /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awk NR==3 | awk '{print $1}'
- }
- function handled {
- /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awk NR==3 | awk '{print $2}'
- }
- function requests {
- /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awk NR==3 | awk '{print $3}'
- }
- # Run the requested function
- $1
- EOF
