用nginx-rrd监控nginx访问数

可以使用cacti、nagios等监控程序监控nginx服务器,不过有时候不用那么复杂,用nginx-rrd就能完成连接、请求的监控功能。

首先编译安装nginx,注意加载stub_status模块,Nginx中的stub_status模块主要用于查看Nginx的一些状态信息.
本模块默认是不会编译进Nginx的,如果你要使用该模块,则要在编译安装Nginx时指定

 
 
  1. tar xzvf nginx-1.2.0.tar.gz  
  2. cd  nginx-1.2.0  
  3. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module  
  4. make && make install 

yum安装相关的perl、rrdtool的rpm包

 
 
  1. yum install perl rrdtool perl-libwww-perl libwww-perl perl-rrdtool 
确定 rrdtool 和相应的perl 被安装上后,开始安装nginx-rrd
 
 
 
  1. tar zxvf nginx-rrd-0.1.4.tgz  
  2. cd nginx-rrd-0.1.4  
  3. cp -p usr/sbin/* /usr/sbin     //复制主程序文件到 /usr/sbin 下  
  4. cp -p etc/nginx-rrd.conf /etc  //复制配置文件到 /etc 下  
  5.  
  6. 创建nginx-rrd生成目录  
  7. mkdir /usr/local/nginx/html/rrd  
  8. cp html/index.php /usr/local/nginx/html  
这里提醒需要修改  index.php文件的默认访问密码WCO。

 

编辑修改/etc/nginx-rrd.conf

 
 
  1. vim /etc/nginx-rrd.conf  
  2.  
  3. #####################################################  
  4. #  
  5. # dir where rrd databases are stored  
  6. RRD_DIR="/usr/local/nginx/html/rrd";  
  7. # dir where png images are presented  
  8. WWW_DIR="/usr/local/nginx/html";  
  9. # process nice level  
  10. NICE_LEVEL="-19";  
  11. # bin dir  
  12. BIN_DIR="/usr/sbin";  
  13. # servers to test  
  14. # server_utl;server_name  
  15. SERVERS_URL="http://www.linuxom.com/nginx_status;www.linuxom.com" 

多个虚拟主机,可以SERVERS_URL中空格分开,前部分为nginx_status 的地址,后面为被监控主机的域名。

查看已安装的nginx是否包含stub_status模块

 
 
  1.  /usr/local/nginx/sbin/nginx -V  
  2. nginx version: Nginx/1.2.0  
  3. configure arguments: --with-http_stub_status_module  

确定支持stub_status模块后编辑修改nginx.conf

 
 
  1. vim /usr/local/nginx/conf/nginx.conf  
  2.  
  3. //server{} 中,需要已经加入如下内容  
  4.  location / {  
  5.             root   html;  
  6.             index  index.php index.html index.htm;  
  7.  
  8.         location /nginx_status {  
  9.             stub_status on;   //这个选项参数就是在编译时对stub_status模块的支持,如果不编译加入则会在启动nginx时有警告信息
  10.             access_log off;  
  11.         }  
  12.  
  13.  
  14.         }  
  15.  
  16.         #error_page  404              /404.html;  
  17.  
  18.         # redirect server error pages to the static page /50x.html  
  19.         #  
  20.         error_page   500 502 503 504  /50x.html;  
  21.         location = /50x.html {  
  22.             root   html;  
  23.         }  
  24.  
  25.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  26.         #  
  27.         #location ~ \.php$ {  
  28.         #    proxy_pass   http://127.0.0.1;  
  29.         #}  
  30.  
  31.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  32.         #  
  33. // 去掉如下内容的注释,这里是对php的支持,注意文件路径 
  34.         location ~ \.php$ {  
  35.             root           html;  
  36.             fastcgi_pass   127.0.0.1:9000;  
  37.             fastcgi_index  index.php;  
  38.             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;  
  39.             include        fastcgi_params;  
  40.         }  

重启Nginx服务器

 
  
  1. /usr/local/nginx/sbin/nginx -s reload  

设置定时收集数据

 
 
  1. crontab -e  
  2. * * * * * root /usr/sbin/nginx-collect  
  3. */10 * * * * root /usr/sbin/nginx-graph 
 
访问页面 http://域名/index.php,nginx的连接数如下图

 

 nginx请求数如下图

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值