lb20309 发表于 2018-1-1 19:34:05

监控系统

  监控系统——zabbix监控Nginx
  前段时间在公司IDC服务器上部署了zabbix3.0.3监控系统,除了自带的内存/带宽/CPU负载等系统资源监控模板以及mysql监控模板外,接下来对ngin监控项配置在此做下记录,希望能帮助到有用到的朋友们~
  nginx的监控模板:zbx_nginx_templates.xml
  监控模板下载地址:http://pan.baidu.com/s/1eSkqyJ4  提取密码:dss8
  1. 添加nginx的监控
# vim /application/nginx/conf/nginx.conf
  

location ~ /NginxStatus {  stub_status on;
  access_log off;
  }
  

  

# /application/nginx/sbin/nginx -t  
[iyunv@LNMP
-01-152 ~]# /application/nginx/sbin/nginx -s>  

  2)zabbix监控nginx的自定义键值
  在客户机的zabbix的monitor_scripts目录下添加nginx-status.sh文件,进行如下配置(这个配置可以适用于其他机器的nginx监控)
  

#!/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
="$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
="-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 '' | cut -f2 -d' ';;  handled_connections) echo
"$NGINX_STATS" | grep -Ev '' | cut -f3 -d' ';;  handled_requests) echo
"$NGINX_STATS" | grep -Ev '' | 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  

  3)配置nginx-status的key文件
  《前提是/application/zabbix/etc/zabbix_agentd.conf里已经定义了Include=/application/zabbix/etc/zabbix_agentd.conf.d/的路径了》
# vim /application/zabbix/etc/zabbix_agentd.conf
  Include=/application/zabbix/etc/zabbix_agentd.userparams.conf
  Include=/application/zabbix/etc/zabbix_agentd.conf.d/
# vim /application/zabbix/etc/zabbix_agentd.conf.d/nginx_status.conf
  UserParameter=nginx
[*],/application/zabbix/monitor_scripts/nginx_status.sh "$1"
  访问web的status进行查看试试
页: [1]
查看完整版本: 监控系统