开发者社区> 机智如我丶> 正文

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~~~
这里写图片描述


这里写图片描述

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
使用zabbix监控nginx服务(十五)
使用zabbix监控nginx服务 1.开启nginx状态监控
142 0
Zabbix监控插件-Nginx、TCP、Redis、Memcached
2014年写的zabbix监控插件,主要监控TCP的11种状态,Nginx的状态,Redis的和Memcached的状态。
236 0
zabbix nginx模板
zabbix服务端nginx的上传文件限制修改:client_max_body_size 5m; nginx 客户端开启状态检测 nginx server { listen 80; server_name localhost; loc...
1507 0
Zabbix添加nginx监控项
##########Nginx配置########## #查看是否安装nginx状态模块 nginx -V #--with-http_stub_status_module #修改配置文件 vim /etc/nginx/nginx.
964 0
Zabbix SNMP自定义OID监控Nginx(学习笔记七)
转载:http://www.ttlsa.com/zabbix/snmp-custom-oid/ 确认SNMP OID是否存在 首先我们需要找一个oid是否被系统暂用,比如.
1219 0
文章
问答
文章排行榜
最热
最新
相关电子书
更多
《Nginx 代理系统常用手册》
立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手
立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册
立即下载