首页 > 代码库 > 分布式监控系统Zabbix-3.0.3-完整安装记录(4)-监控nginx,php,memcache,Low-level discovery磁盘IO

分布式监控系统Zabbix-3.0.3-完整安装记录(4)-监控nginx,php,memcache,Low-level discovery磁盘IO

 

 

前段时间在公司IDC服务器上部署了zabbix3.0.3监控系统,除了自带的内存/带宽/CPU负载等系统资源监控模板以及mysql监控模板外,接下来对诸如nginx、php、memcache、磁盘IO的监控项配置在此做下记录,希望能帮助到有用到的朋友们~

 

nginx的监控模板:zbx_nginx_templates.xml
php的监控模板:zbx_php-fpm_templates.xml
memcache的监控模板:zbx_memcached_templates.xml
Low-level discovery监控磁盘IO的监控模板:Template Linux DiskIO.xml

以上四个监控项的模板的下载地址:http://pan.baidu.com/s/1geAMZfl (提取密码:zpyx)

--------------------------------------------------------------------------------------------------
一、配置nginx的监控
1)首先在客户机的nginx配置文件里添加:
[root@115r ~]# vim www.world.huanqiu.conf
.......
location /nginx_status {
stub_status on;
access_log off;
}
........

添加后,重启nginx服务:
[root@115r ~]#/usr/local/nginx/sbin/nginx -s reload

2)zabbix监控nginx的自定义键值

在客户机的zabbix的monitor_scripts目录下添加nginx-status.sh文件,进行如下配置(这个配置可以适用于其他机器的nginx监控)
[root@115r ~]# cd /usr/local/zabbix/monitor_scripts/
[root@115r monitor_scripts]#cat nginx-status.sh
#!/bin/bash
##################################
# Zabbix monitoring script
#
# nginx:
# - anything available via nginx stub-status module
#
##################################
# Contact:
# vincent.viallet@gmail.com
##################################
# ChangeLog:
# 20100922 VV initial creation
##################################

# Zabbix requested parameter
ZBX_REQ_DATA="http://www.mamicode.com/$1"
ZBX_REQ_DATA_URL="$2"

# Nginx defaults
URL="http://127.0.0.1/nginx_status"
WGET_BIN="/usr/bin/wget"

#
# Error handling:
# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
# - items need to be of type "float" (allow negative + float)
#
ERROR_NO_ACCESS_FILE="-0.9900"
ERROR_NO_ACCESS="-0.9901"
ERROR_WRONG_PARAM="-0.9902"
ERROR_DATA="http://www.mamicode.com/-0.9903" # either can not connect /         bad host / bad port

# save the nginx stats in a variable for future parsing
NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)

# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
echo $ERROR_DATA
exit 1
fi

#
# Extract data from nginx stats
#
case $ZBX_REQ_DATA in
active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d‘ ‘;;
accepted_connections) echo "$NGINX_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f2 -d‘ ‘;;
handled_connections) echo "$NGINX_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f3 -d‘ ‘;;
handled_requests) echo "$NGINX_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f4 -d‘ ‘;;
reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d‘ ‘;;
writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d‘ ‘;;
waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d‘ ‘;;
*) echo $ERROR_WRONG_PARAM; exit 1;;
esac

exit 0

 

分布式监控系统Zabbix-3.0.3-完整安装记录(4)-监控nginx,php,memcache,Low-level discovery磁盘IO