QQ叫紫珊 发表于 2015-11-23 14:06:18

利用Zabbix监控Nginx

利用Zabbix监控Nginx

转自

http://www.iyunv.com/Linux/2012-07/64798.htm









近段时间一直在使用zabbix,让其监控更多的东西,目前我也在一步一步实现原计划。不得不说它的自由定制功能真是很强!开工吧。

实现监控需要三个步骤:

1、自己创建或是导入模版。<附件>

2、nginx需要配置status。

这个因环境而已,我贴上我的吧。


[*]server {
[*]listen 80;
[*]server_name xxx.xxx.xxx.xxx;
[*]index index.html login.jsp;
[*]root /www/freetrade;
[*]access_log off;
[*]error_log off;
[*]location /nginx {
[*]stub_status on;
[*]access_log off;
[*]allow 127.0.0.1;
[*]allow xxx.xxx.xxx.xxx;
[*]deny all;
[*]}
[*]}


3、改客户端配置文件,使用脚本。

在客户端机器上任意位置放这个脚本,不过我还是建议你规范的放在一个地方。我在作者的基础上改了一下,适合自己的需求。


[*]#!/bin/bash
[*]# Script to fetch nginx statuses for tribily monitoring systems
[*]# Author: krish@toonheart.com
[*]# License: GPLv2
[*]
[*]# Set Variables
[*]HOST=`/sbin/ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
[*]PORT=&quot;80&quot;
[*]
[*]# Functions to return nginx stats
[*]
[*]function active {
[*]/usr/bin/curl &quot;http://$HOST:$PORT/nginx&quot; 2 > /dev/null| grep 'Active' | awk '{print $NF}'
[*]}
[*]
[*]function reading {
[*]/usr/bin/curl &quot;http://$HOST:$PORT/nginx&quot; 2 > /dev/null| grep 'Reading' | awk '{print $2}'
[*]}
[*]
[*]function writing {
[*]/usr/bin/curl &quot;http://$HOST:$PORT/nginx&quot; 2>/dev/null| grep 'Writing' | awk '{print $4}'
[*]}
[*]
[*]function waiting {
[*]/usr/bin/curl &quot;http://$HOST:$PORT/nginx&quot; 2 > /dev/null| grep 'Waiting' | awk '{print $6}'
[*]}
[*]
[*]function accepts {
[*]/usr/bin/curl &quot;http://$HOST:$PORT/nginx&quot; 2 > /dev/null| awk NR==3 | awk '{print $1}'
[*]}
[*]
[*]function handled {
[*]/usr/bin/curl &quot;http://$HOST:$PORT/nginx&quot; 2 > /dev/null| awk NR==3 | awk '{print $2}'
[*]}
[*]
[*]function requests {
[*]/usr/bin/curl &quot;http://$HOST:$PORT/nginx&quot; 2 > /dev/null| awk NR==3 | awk '{print $3}'
[*]}
[*]
[*]# Run the requested function
[*]$1


修改客户端/etc/zabbix/zabbix_agentd.conf 环境不同,文件位置不同。


[*]#monitor nginx
[*]UserParameter=nginx.accepts,/etc/zabbix/scripts/nginx_status accepts
[*]UserParameter=nginx.handled,/etc/zabbix/scripts/nginx_status handled
[*]UserParameter=nginx.requests,/etc/zabbix/scripts/nginx_status requests
[*]UserParameter=nginx.connections.active,/etc/zabbix/scripts/nginx_status active
[*]UserParameter=nginx.connections.reading,/etc/zabbix/scripts/nginx_status reading
[*]UserParameter=nginx.connections.writing,/etc/zabbix/scripts/nginx_status writing
[*]UserParameter=nginx.connections.waiting,/etc/zabbix/scripts/nginx_status waiting



有图才有真相!<几台空闲的nginx>



相关附件下载

免费下载地址在 http://linux.iyunv.com/

用户名与密码都是www.iyunv.com

具体下载目录在 /2012年资料/7月/9日/利用Zabbix监控Nginx/
页: [1]
查看完整版本: 利用Zabbix监控Nginx