zabbix3.0.4监控nginx服务

Zabbix3.0.4添加对Nginx服务的监控

一、

通过Nginx的http_stub_status_module模块提供的状态信息来监控,所以在Agent端需要配置Nginx状态获取的脚本,和添加key信息等,然后在Server端配置Nginx的监控模板等。请根据自己情况调整,这里只做简单的参照。

主要是使用Github这个项目的代码 zabbix-templates

检查Nginx是否安装了 http_stub_status_module 模块,通过下面的命令可以看到编译参数。

如没有http_stub_status_module 模块,请重新编译加上该模块

二、

配置nginx如下图

重启nginx   /usr/local/nginx/sbin/nginx -s reload

查看如下

三、

1.nginx脚本 cat nginx-check.sh

#!/bin/bash
##################################
# Zabbix monitoring script
#
# nginx:
#  - anything available via nginx stub-status module
#
##################################
# Contact:
#  [email protected]
# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"
# Nginx defaults
NGINX_STATUS_DEFAULT_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
# 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

给脚本权限

chmod +x  nginx-check.sh

2. agent的配置文件 /usr/local/zabbix-3.0.4/etc/zabbix_agentd.conf 中定义了其他key的包含目录
Include=/usr/local/zabbix-3.0.4/etc/zabbix_agentd.d/, 如果没有这个配置请自己添加下。接着在
/usr/local/zabbix-3.0.4/etc/zabbix_agentd.d/ 目录新建一个文件 nginx-params.conf, 内容如下

cat nginx-params.conf

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

3.重启zabbix_agent

四、

server端测试

web界面导入模板

在web端查看监控

注: 模板地址https://github.com/jizhang/zabbix-templates/blob/master/nginx/nginx-template.xml

时间: 2024-08-06 03:42:51

zabbix3.0.4监控nginx服务的相关文章

zabbix3.0.4监控nginx性

在zabbix agentd客户端上,查看nginx是否加载了–with-http_stub_status_module.因为zabbix监控nginx是根据nginx的Stub Status模块,抓取Status模块所提供的数据.假如以前没开启,现在想启用StubStatus 模块,在编译nginx 的时候要加上参数 –with-http_stub_status_module,执行./configure && make就可以了,不用make install.不过,一般情况下都是安装了的.

Nagios监控nginx服务具体过程

1在nginx 服务器上安装nrpe客户端: Nginx的服务须要监控起来.不然万一down了而不及时修复,会影响web应用.例如以下web应用上面启动的nginx后台进程[[email protected] ~]# ps aux|grep nginxnobody   15294  0.0  0.0  22432  3464 ?        S    Jul03   0:05 nginx: worker process      nobody   15295  0.0  0.0  22432

Python 监控nginx服务是否正常

Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True: try: ret = os.popen('ps -C nginx -o pid,cmd').readlines() if len(ret) <2: os.system("service nginx start") sys.exit(0) except Exception,ex:

Nagios监控nginx服务详细过程

1在nginx 服务器上安装nrpe客户端: Nginx的服务需要监控起来,不然万一down了而不及时修复,会影响web应用,如下web应用上面启动的nginx后台进程[[email protected] ~]# ps aux|grep nginxnobody   15294  0.0  0.0  22432  3464 ?        S    Jul03   0:05 nginx: worker process      nobody   15295  0.0  0.0  22432  3

Zabbix3.0.4监控Windows的CPU使用百分比并在CPU使用率超过90%触发报警

Zabbix3.0.4监控Windows的CPU使用百分比 Zabbix 自带的模块没有 CPU 使用率(百分比)这个监控项,我们可以通过添加计数器的方式实现 CPU 百分比的监控. 1.在Zabbix 的 WEB 端进行模板配置添加 CPU 百分比监控项目 *. 配置–模块–选择对应的模板–项目–创建项目 名称:CPU 百分比键值:perf_counter[\Processor(_Total)\% Processor Time]数据类型:数字的(浮点)单位:%数据更新间隔(秒):30应用集:C

centos7 搭建zabbix3.0.5监控系统

一.实验环境: [[email protected] ~]# cat /etc/redhat-release  CentOS Linux release 7.2.1511 (Core)  [[email protected] ~]# uname -r 3.10.0-327.el7.x86_64 [[email protected] ~]# [[email protected] ~]# ifconfig eno16777736 eno16777736: flags=4163<UP,BROADCAS

linux运维学习shell脚本监控nginx服务

菜鸟学习shell脚本后,动手练手简单小实验,使用shell脚本判断nginx是否正常运行,如果没有运行将nginx服务启动起来. 一.基于进程判断 1.获取nginx进程来判断该服务是否正常启动. ps -ef | grep nginx | grep -v grep | wc -l    输出进程行数 然后判断是否为2 如果不是说明该服务没有启动. grep -v grep  用来排除掉您所使用grep产生的进程. 2.shell 脚本编写 先定义一个变量Web #!/bin/bash Web

【zabbix告警监控】配置zabbix监控nginx服务

zabbix监控nginx,nginx需要添加--with-http_stub_status模块 使用zabbix监控nginx,首先nginx需要配置开启ngx_status.但是我这边nginx安装成功了并且也没有添加sub模块,需要重新编译添加该模块.配置如下: # 在添加之前需要查看是否有sub的模块(--with-http_sub_module 这个模块),如果没有就需要重新编译 # 使用nginx -V可以查看 [[email protected]_0_10_centos thy]#

【CNMP系列】CentOS7.0下安装Nginx服务

话步前言,CNMP之路,系统起步:http://www.cnblogs.com/riverdubu/p/6425028.html 这回我来讲解下CentOS7.0下如何安装和配置Nginx服务 Nginx的历史不在此赘述,轻量,快是它的特性.只是因为现在的模块没有达到apache的模块数量级,未来有超越apache的势头. 首先,我们要安装个必要的软件(上节提到过,可能有人并未安装) #yum install wget 因为Nginx以来与gcc的编译环境,所以,在mini centos中需要安