Zabbix监控Nginx性能状态(2)

CentOS 7.2 安装部署 Zabbix 3.0.4 详解 

Ubuntu 14.04下Zabbix2.4.5 源码编译安装  .com/Linux/2015-05/117657.htm

CentOS 6.8下Zabbix Server 安装部署详细步骤

Zabbix基本配置及监控主机

CentOS 7.0 x64下Zabbix 3.0 安装笔记 

CentOS下Zabbix 3.0.4安装部署

CentOS 7 LNMP环境搭建Zabbix3.0

64位CentOS 6.2下安装Zabbix 2.0.6   

(二)配置zabbix_agentd

1,编写脚步来获取nginx的相关信息

[root@ittestserver1 opt]# vim /usr/local/zabbix/scripts/nginx-check_performance.sh

#!/bin/bash

##################################

# Zabbix monitoring script

#

# nginx:

# - anything available via nginx stub-status module

#

##################################

# Contact:

# vincent.viallet@gmail.com

# Zabbix requested parameter

ZBX_REQ_DATA="$1"

ZBX_REQ_DATA_URL="$2"

# Nginx defaults

NGINX_STATUS_DEFAULT_URL="www.linuxidc.com/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

# Handle host and port if non-default

if [ ! -z "$ZBX_REQ_DATA_URL" ]; then

URL="$ZBX_REQ_DATA_URL"

else

URL="$NGINX_STATUS_DEFAULT_URL"

fi

# 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

[root@ittestserver1 opt]# chmod +x /usr/local/zabbix/scripts/nginx-check_performance.sh

-rw-r--r-x1 root root 1645 2月 4 14:26/usr/local/zabbix/scripts/nginx-check_performance.sh

2,配置zabbix_agentd.conf。启用UserParameter,并配置相关的参数。

[root@ittestserver1 opt]# vim /usr/local/zabbix/etc/zabbix_agentd.conf

####### USER-DEFINED MONITORED PARAMETERS #######

### Option: UnsafeUserParameters

#      Allow all characters to be passed in arguments to user-defined parameters.

#      The following characters are not allowed:

#      \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @

#      Additionally, newline characters are not allowed.

#      0 - do not allow

#      1 - allow

#

# Mandatory: no

# Range: 0-1

# Default:

# UnsafeUserParameters=0

UnsafeUserParameters=1

### Option: UserParameter

#      User-defined parameter to monitor. There can be several user-defined parameters.

#      Format: UserParameter=<key>,<shell command>

#      See 'zabbix_agentd' directory for examples.

#

# Mandatory: no

# Default:

# UserParameter=

UserParameter=nginx[*],/usr/local/zabbix/scripts/nginx-check_performance.sh "$1"

3,重启zabbix_agentd客户端

[root@zabbix ~]# /etc/init.d/zabbix_agentd restart

Shutting down zabbix_agentd:                              [  OK  ]

Starting zabbix_agentd:                                    [  OK  ]

[root@zabbix ~]#


4,在zabbix服务端(server)进行测试。

[root@zabbix ~]# zabbix_get -s 10.253.17.20 -p 10050 -k "nginx[reading]"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b2f0d48428651ee1f909b228ad9a8c5c.html