Zabbix 监控 Nginx

Zabbix监控Nginx

首先,大家如果看到有什么不懂的地方,欢迎吐槽!!!
我会在当天或者第二天及时回复,并且改进~~


在添加监控之前,必须要强调的是,Nginx必须支持stub_status状态的访问,不然一切都是空谈!!!

首先zabbix监控nginx 是根据nginx的Stub Status模块,抓取Status模块所提供的数据。
如果想启用Stub Status模块,在编译nginx的时候要加上参数 
--with-http_stub_status_module 

例如:
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
在Nginx配置档中添加:
     location /nginx_status {
                stub_status on;
                access_log   off;
                }

一、创建监控Nginx的key

  • nginx_status_key
vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx_status_key

UserParameter=nginx.accepts,/usr/local/zabbix/shell/nginx_status.sh accepts 
UserParameter=nginx.handled,/usr/local/zabbix/shell/nginx_status.sh handled 
UserParameter=nginx.requests,/usr/local/zabbix/shell/nginx_status.sh requests 
UserParameter=nginx.connections.active,/usr/local/zabbix/shell/nginx_status.sh active 
UserParameter=nginx.connections.reading,/usr/local/zabbix/shell/nginx_status.sh reading 
UserParameter=nginx.connections.writing,/usr/local/zabbix/shell/nginx_status.sh writing 
UserParameter=nginx.connections.waiting,/usr/local/zabbix/shell/nginx_status.sh waiting

二、创建监控Nginx的脚本(记得加执行权限)

  • nginx_status.sh
vim /usr/local/zabbix/shell/nginx_status.sh

#!/bin/bash 
# Script to fetch nginx statuses for tribily monitoring systems 
# License: GPLv4 
# Set Variables 
BKUP_DATE=`/bin/date +%Y%m%d` 
LOG="/usr/local/zabbix/logs/nginx_status.log" 
HOST="192.168.0.217"        #HOST非常重要,确保CURL能访问到这个IP地址的Status
PORT="80" 

# Functions to return nginx stats 
function active { 
    /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Active' | awk '{print $NF}'       
    }     
function reading { 
    /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Reading' | awk '{print $2}'       
    }     
function writing { 
    /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Writing' | awk '{print $4}'       
    }     
function waiting { 
    /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'       
    }     
function accepts { 
    /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $1}' 
    }     
function handled { 
    /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $2}' 
    }       
function requests { 
    /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $3}' 
    } 
# Run the requested function 
$1 

三、在Zabbix Web界面中创建Templates App Nginx模版
(1)、先创建三个item,这个store value要求是每秒变化的

  • nginx.accepts
  • nginx.handled
  • nginx.requests
我在这边做一个示例:
模版中添加一个nginx.accepts的item

Name                nginx.accepts  
Type                Zabbix agent
Key                 nginx.accepts
Type of information Numeric (unsigned)
Data Type           Decimal
Units               空
Store value         Detal (speed per second)
Show  value         As is 

(2)、而后四个item Store value是不变的

  • nginx.connections.active
  • nginx.connections.reading
  • nginx.connections.writing
  • nginx.connections.waiting
Name                nginx.connections.active
Type                Zabbix agent
Key                 nginx.accepts
Type of information Numeric (unsigned)
Data Type           Decimal
Units               空
Store value         As is
Show  value         As is 

创建完大概是这个样子,相信新手也能做出来!!!
这里写图片描述


四、现在点击要Tempates的Graphs,分别创建两个Graphs

监控Nginx(nginx.accepts、nginx.handled、nginx.requests)
监控Nginx(nginx.connections.active、nginx.connections.reading、nginx.connections.writing、nginx.connections.waiting)

图像1:暂且取名为 Nginx_Interactive
这里写图片描述
图像2:暂且取名为 Nginx_Connection
这里写图片描述


五、Hosts-Templates-将刚才创建的Templates App Nginx链接到主机上面
完成之后大概是这个样子
这里写图片描述


六、在Screen中创建监控Nginx的Screen,将前面创建的两个图像添加进去

这里写图片描述


七、这时候在Zabbix Web页面中查看Nginx状态就OK~~~
这里写图片描述


这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值