zoukankan      html  css  js  c++  java
  • 用nginxrrd监控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请求数如下图

  • 相关阅读:
    ubuntu下erlang man的安装
    ranch分析学习(四)
    ranch分析学习(三)
    ranch分析学习(二)
    ranch分析学习(一)
    IIS 配置错误解决方法集合
    Visual Studio 2013中添加mimeType
    wordpress 开发日志及技巧收集
    css3 动画
    高宽比例计算方法及等比高宽修改计算方法
  • 原文地址:https://www.cnblogs.com/kgdxpr/p/3075031.html
Copyright © 2011-2022 走看看