Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1760383
  • 博文数量: 150
  • 博客积分: 660
  • 博客等级: 上士
  • 技术积分: 2480
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-08 11:39
文章分类

全部博文(150)

文章存档

2019年(4)

2018年(36)

2017年(53)

2016年(7)

2015年(3)

2014年(3)

2013年(27)

2012年(2)

2011年(1)

2006年(1)

2005年(13)

分类: 系统运维

2012-11-15 16:34:01

nginx for zabbix 安装步骤 

一、zabbix server端安装
1、下载ztc for zabbix 安装包  
2、从安装包的templates中导入nginx的模板文件,禁用nginx.ping
3、后附模板文件内容   
   
主要利用其模版和自定义脚本,自定义脚本可以自己写
二、zabbix client端安装
1、修改zabbix_agentd.conf 增加自定义key设置


#UserParameter=nginx.ping,/opt/ztc/bin/nginx.py ping

#UserParameter=nginx.accepts,/opt/ztc/bin/nginx.py accepts
#UserParameter=nginx.handled,/opt/ztc/bin/nginx.py handled
#UserParameter=nginx.requests,/opt/ztc/bin/nginx.py requests
#UserParameter=nginx.connections.active,/opt/ztc/bin/nginx.py connections_active
#UserParameter=nginx.connections.reading,/opt/ztc/bin/nginx.py connections_reading
#UserParameter=nginx.connections.writing,/opt/ztc/bin/nginx.py connections_writing
#UserParameter=nginx.connections.waiting,/opt/ztc/bin/nginx.py connections_waiting


UserParameter=nginx.accepts,/home/zabbix/nginx-status.sh accepts
UserParameter=nginx.handled,/home/zabbix/nginx-status.sh handled
UserParameter=nginx.requests,/home/zabbix/nginx-status.sh requests
UserParameter=nginx.connections.active,/home/zabbix/nginx-status.sh active
UserParameter=nginx.connections.reading,/home/zabbix/nginx-status.sh reading
UserParameter=nginx.connections.writing,/home/zabbix/nginx-status.sh writing
UserParameter=nginx.connections.waiting,/home/zabbix/nginx-status.sh waiting

2、增加zabbix 自定义key使用的nginx-status.sh脚本
cd /home/zabbix
vi nginx-status.sh
#!/bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author: krish@toonheart.com
# License: GPLv2

# Set Variables
BKUP_DATE=`date +%Y%m%d`
LOG="/var/log/zabbix/webstatus.log"
#HOST=`ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
HOST=127.0.0.1
webstatus=nginx-status
PORT="80"

# Functions to return nginx stats

function active {
        elinks -source "" | grep 'Active' | awk '{print $NF}'        
        }      

function reading {
        elinks -source "" | grep 'Reading' | awk '{print $2}'        
        }      

function writing {
        elinks -source "" | grep 'Writing' | awk '{print $4}'        
        }      

function waiting {
        elinks -source "" | grep 'Waiting' | awk '{print $6}'        
        }      

function accepts {
        elinks -source "" | awk NR==3 | awk '{print $1}'
        }      

function handled {
        elinks -source "" | awk NR==3 | awk '{print $2}'
        }      

function requests {
        elinks -source "" | awk NR==3 | awk '{print $3}'
        }

# Run the requested function
$1
增加运行权限和改变属主
chmod+x nginx-status.sh
chown -R zabbix:zabbix nginx-status.sh
3、重启 zabbix_agentd
pkill -9 zabbix_agentd
/usr/local/sbin/zabbix_agentd
4、安装 nginx-status.sh脚本用到的elinks
yum install elinks
5、检查nginx.conf 增加如下配置
vi /usr/local/nginx/conf/nginx.conf
        location /nginx-status {
                stub_status on;
                access_log   off;
                allow 127.0.0.1;
                deny all;
        }
        
       重启nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload 
7?¢2?
elinks -source
Active connections: 1 
server accepts handled requests
27 27 129 
Reading: 0 Writing: 1 Waiting: 0 

nginx status说明

stub_status

语法: stub_status on

默认值: None

作用域: location

创建一个 location 区域启用 stub_status

"stub status" 模块返回的状态信息跟 mathopd's 的状态信息很相似. 返回的状态信息如下:

Active connections: 291
server accepts handled requests
: 16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106

active connections -- 对后端发起的活动连接数

server accepts handled requests -- nginx 总共处理了 16630948 个连接, 成功创建 16630948 次握手 (证明中间没有失败的), 总共处理了 31070465 个请求 (平均每次握手处理了 1.8个数据请求)

reading -- nginx 读取到客户端的Header信息数

writing -- nginx 返回给客户端的Header信息数

waiting -- 开启 keep-alive 的情况下,这个值等于 active - (reading + writing),意思就是Nginx说已经处理完正在等候下一次请求指令的驻留连接 

三、nginx?模版内容


0
0
0.0.0.0
10050
3
0
127.0.0.1
623
-1
2
Templates
nginx is down on {HOSTNAME}
0
{Template_app_nginx:nginx.ping.last(0)}=0
0
4
Nginx is not available via configured url
nginx is down on {HOSTNAME}
0
{Template_app_nginx:proc.num[nginx].last(0)}=0
0
4
Nginx: requests per second
90
7
365
0
0
1
1
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Nginx: handled per second
90
7
365
0
0
1
1
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Nginx active connections
90
7
365
0
0
0
0
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Nginx: number of connections in reading state
90
7
365
0
0
0
0
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Nginx: number of connections in writing state
90
7
365
0
0
0
0
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Nginx: number of connections in waiting state
90
7
365
0
0
0
0
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Nginx ping
60
90
365
0
0
s
0
0
1
0
0
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Nginx: accepts per second
90
7
365
0
0
1
1
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
Number of nginx running
90
9
365
0
0
0
0
1
0
0
DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>
public
interfaces.ifTable.ifEntry.ifInOctets.1
161
0
nginx
1
0
0
0
0
0.0000
100.0000
0
0
0.0000
0.0000
2
0
009900
0
2
0
5
0
0
1
1
0
0.0000
100.0000
0
0
0.0000
0.0000
0
0
FF0000
0
2
0
5
0
0
3333FF
0
2
0
5
0
0
009900
0
2
0
5
0
0
0
0
0
0.0000
100.0000
0
0
0.0000
0.0000
2
0
009900
0
2
0
5
0
0
FF3333
0
2
0
5
0
0
FF33FF
0
2
0
5
0
0
0000FF
0
2
0
5
阅读(5138) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~