最新消息:

Nginx状态监控总结

优化监控 admin 1浏览

今天在整理编写nginx tips,简单的再次把nginx相关监控资料整理一下供大家参考,希望大家玩的开心,做出更强大的东西!

1、RRDTOOL+Perl脚本画图监控
先安装好rrdtool ,关于rrdtool本文不作介绍,具体安装请参照linuxtone监控版块.

cd/usr/local/sbnin

wget http://blog.kovyrin.net/files/mrtg/rrd_nginx.pl.txt

mv rrd_nginx.pl.txtrrd_nginx.pl

chmod a+x rrd_nginx.pl

vi rrd_nginx.pl

//配置脚本文件设置好路径

!/usr/bin/perl

use RRDs;
useLWP::UserAgent;

definelocation of rrdtool databases

my $rrd =’/data/www/wwwroot/nginx/rrd’;

definelocation of images

my $img =’/data/www/wwwroot/nginx/html’;

defineyour nginx stats URL

my $URL =”http://219.232.244.13/nginx_status”;
…………

【注】根据自己具体的状况修改相应的路径.

crontab –e //加入如下

        • */usr/local/sbin/rrd_nginx.pl

重启crond后,通过配置nginx虚拟主机指到/data/www/wwwroot/nginx/html目录,通过crond自动执行perl脚本会生成很多图片.
http://xxx/connections-day.png即可看到服务器状态图。

2、官方Nginx-rrd 监控服务(多虚拟主机)(推荐)
网址:http://www.nginx.eu/nginx-rrd.html
此解决方案其实是基于上述监控方案的一个改进和增强,同样先安装好rrdtool这个画图工具和相应的perl模块再做如下操作:

yum install perl-HTML*

先建立好生成的库存和图片存放录

mkdir -p/data/www/wwwroot/nginx/{rrd,html}

cd/usr/local/sbin

wget http://www.nginx.eu/nginx-rrd/nginx-rrd-0.1.4.tgz

tar zxvfnginx-rrd-0.1.4.tgz

cd nginx-rrd-0.1.4

cd etc/

cp nginx-rrd.conf /etc

cd etc/cron.d

cp nginx-rrd.cron /etc/cron.d

cd /usr/local/src/nginx-rrd-0.1.4/html

cp index.php /data/www/wwwroot/nginx/html/

cd /usr/local/src/nginx-rrd-0.1.4/usr/sbin

cp * /usr/sbin/

vi /etc/nginx-rrd.conf

dirwhere rrd databases are stored

RRD_DIR=”/data/www/wwwroot/nginx/rrd”;

dirwhere png images are presented

WWW_DIR=”/data/www/wwwroot/nginx/html”;

processnice level

NICE_LEVEL=”-19″;

bin dir

BIN_DIR=”/usr/sbin”;

serversto test

server_utl;server_name

SERVERS_URL=”http://219.32.205.13/nginx_status;219.32.205.13
http://www.linuxtone.org/nginx_status;www.linuxtone.org””
//根据你的具体情况做调整.

SEVERS_URL 格式http://domain1/nginx_status;domain1 http://domain2/nginx_status;domain2
这种格式监控多虚拟主机连接状态:
重点启crond服务,仍后通过http://219.32.205.13/nginx/html/
即可访问。配置过程很简单!

配置过程很简单 ,你也可以试试!

3、CACTI模板监控Nginx
利用Nginx_status状态来画图实现CACTI监控
nginx编译时允许http_stub_status_module

vi /usr/local/nginx/conf/nginx.conf

location/nginx_status {
stub_statuson;
access_logoff;
allow192.168.1.37;
deny all;
}

kill-HUP cat /usr/local/nginx/logs/nginx.pid

wgethttp://forums.cacti.net/download.php?id=12676

tarxvfz cacti-nginx.tar.gz

cpcacti-nginx/get_nginx_socket_status.pl /data/cacti/scripts/

cpcacti-nginx/get_nginx_clients_status.pl /data/cacti/scripts/

chmod755 /data/cacti/scripts/get_nginx*

检测插件

/data/cacti/scripts/get_nginx_clients_status.plhttp://192.168.1.37/nginx_status

在cacti管理面板导入
cacti_graph_template_nginx_clients_stat.xml
cacti_graph_template_nginx_sockets_stat.xml 相关日志升级最新 Nginx Mysql Php
Nginx 使用 User_Agent 阻止恶意评论
Tcmalloc 优化 Nginx Mysql
Nginx perl cgi 支持
快速了解Apache环境

转载请注明:爱开源 » Nginx状态监控总结