cheng029 发表于 2012-10-24 11:23:14

zabbix监控nginx_status

环境:
zabbix 2.0
Zabbix Server: 172.28.2.119
Zabbix nginx 客户端: 172.28.2.151
前提是nignx在编译安装时加上:--with-http_stub_status_module -----这个大家都知道!!同时还要在nginx的配置文件中加上:
[*]location /status
[*]    {
[*]       stub_status on;
[*]       access_lod off;
[*]       allow 127.0.0.1;
[*]       allow 172.28.2.119;    #这是我们zabbix监控服务器IP
[*]    }
下面说下zabbix对nginx的监控原理:Zabbix Server <---(Zabbix Agent)---> nginx客户端key(要写入客户端配置文件中) <--- 脚本 --->nginx状态参数nginx web界面nginx状态显示情况如下图:
< !---->
1.创建获取nginx的status参数数据传送到server端脚本
[*]# cat >> /usr/local/sbin/nginx_status.sh << EOF
[*]#!/bin/bash
[*]# Script to fetch nginx statuses for tribily monitoring systems
[*]# License: GPLv4
[*]# Set Variables
[*]BKUP_DATE=`/bin/date +%Y%m%d`
[*]LOG="/etc/zabbix/nginx_status.log"
[*]#HOST=`/sbin/ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
[*]HOST=`/sbin/ifconfig eth0 |grep "inet addr" |awk -F[:" "] '{print $13}'`
[*]PORT="80"
[*]
[*]# Functions to return nginx stats
[*]function active {
[*]    /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Active' | awk '{print $NF}'
[*]    }
[*]function reading {
[*]    /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Reading' | awk '{print $2}'
[*]    }
[*]function writing {
[*]    /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Writing' | awk '{print $4}'
[*]    }
[*]function waiting {
[*]    /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
[*]    }
[*]function accepts {
[*]    /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awk NR==3 | awk '{print $1}'
[*]    }
[*]function handled {
[*]    /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awk NR==3 | awk '{print $2}'
[*]    }
[*]function requests {
[*]    /usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awk NR==3 | awk '{print $3}'
[*]    }
[*]# Run the requested function
[*]$1
[*]EOF
关于对于这个脚本的解释:这个脚本当中定义了一些状态项名称的函数,函数的功能是通过curl这个工具抓取到nginx web页面的状态数据。2.添加agent客户端key值,以便让zabbix server获取状态数据

[*]# cat >>/etc/zabbix/zabbix_agentd.conf<< EOF
[*]#nginx_status_key
[*]UserParameter=nginx.accepts,/usr/local/sbin/nginx_status.sh accepts
[*]UserParameter=nginx.handled,/usr/local/sbin/nginx_status.sh handled
[*]UserParameter=nginx.requests,/usr/local/sbin/nginx_status.sh requests
[*]UserParameter=nginx.connections.active,/usr/local/sbin/nginx_status.sh active
[*]UserParameter=nginx.connections.reading,/usr/local/sbin/nginx_status.sh reading
[*]UserParameter=nginx.connections.writing,/usr/local/sbin/nginx_status.sh writing
[*]UserParameter=nginx.connections.waiting,/usr/local/sbin/nginx_status.sh waitin
[*]EOF
在此配置文件中,定义了几个UserParameter,这些UserParameter的值就是对应的key,这在我们后面添加Items项当中的 Key 字段要对应,如下图标记处显示:
3.我们可以通过在 zabbix server 端的shell命令行来进行测试:# zabbix_get -s 172.28.2.151 -p 10050 -k "nginx.connections.active"1如果能获取到数据说明配置成功!4.接下来就是在监控端对nginx客户端进行配置基本流程:创建主机--->创建Items--->创建Graphs--->加入到Screens

fjptec-xm 发表于 2013-3-13 16:37:00

支持一下:lol

gdx 发表于 2013-5-15 18:48:57

锻炼肌肉,防止挨揍!

8244 发表于 2013-5-16 12:15:00

要是我灌水,就骂我“三个代表”没学好吧。

joozh 发表于 2013-5-17 08:46:24

站的更高,尿的更远。

我很黑! 发表于 2013-5-18 02:12:21

好好 学习了 确实不错

dream789 发表于 2013-5-18 21:16:03

我是个凑数的。。。
页: [1]
查看完整版本: zabbix监控nginx_status