zoukankan      html  css  js  c++  java
  • 开启nginx状态监控

    开启nginx状态监控

    1.nginx的ngx_http_stub_status_module提供能够获取Nginx自上次启动以来的工作状态 的功能。

      www.ahlinux.com  

    如果是编译安装的话,需要–with-http_stub_status_module激活

    2.该模块是基于某个server的,所以必须在server里面

    3.nginx.conf配置

    01

    server

    02

      {

    03

        listen       80;

    04

        server_name  blog.xfz.com;

    05

        index index.html index.htm index.php;

    06

        root  /data0/htdocs/blog;

    07

    08

        #limit_conn   crawler  20;

    09

    10

        location ~ .*.(php|php5)?$

    11

        {

    12

          #fastcgi_pass  unix:/tmp/php-cgi.sock;

    13

          fastcgi_pass  127.0.0.1:9000;

    14

          fastcgi_index index.php;

    15

          include fcgi.conf;

    16

        }

    17

    18

        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

    19

        {

    20

          expires      30d;

    21

        }

    22

    23

        location ~ .*.(js|css)?$

    24

        {

    25

          expires      1h;

    26

        }

    27

        location /nginx_status {

    28

            stub_status on;

    29

            access_log off;

    30

            allow 192.168.1.1;#设置为可访问该状态信息的ip

    31

            deny all;

    32

        }  

    33

        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '

    34

                  '$status $body_bytes_sent "$http_referer" '

    35

                  '"$http_user_agent" $http_x_forwarded_for';

    36

        access_log  /data1/logs/access.log  access;

    37

          }

    38

      

    其中状态的配置

    1

    location /nginx_status {

    2

          stub_status on;

    3

          access_log off;

    4

          allow 192.168.1.1;#设置为可访问该状态信息的ip

    5

          deny all;

    6

      } 

    1

    然后,reload一下nginx的配置

    2

    通过http://blog.xfz.com<span></span>/nginx_status 即可访问

    状态值:

    Active connections: 1 

    server accepts handled requests

     14 14 21 

    Reading: 0 Writing: 1 Waiting: 0 

    解释: 

    active connections:nginx 正处理的活动连接数 20个。 

    server accepts handled requests:nginx启动到现在共处理了 200个连接 , 成功创建 200 次握手 一般跟第一个一样,差值为请求丢失数, 总共处理了286 次请求。 

    reading :nginx 读取到客户端的 Header 信息数。 

    writing : nginx 返回给客户端的 Header 信息数。 

    waiting :开启 keep-alive 的情况下,这个值等于 active - (reading + writing),意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接。

    这个状态信息,从nginx启动算起,包括重载配置文件,也会清零

    也可以通过命令查看

    01

    #netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’

    02

    03

    04

     TIME_WAIT 17

    05

    ESTABLISHED 3254

    06

    LAST_ACK 236

    07

    FIN_WAIT_1 648

    08

    FIN_WAIT_2 581

    09

    CLOSING 7

    10

    CLOSE_WAIT 4916

    11

    12

    解析:

    13

    CLOSED  //无连接是活动的或正在进行

    14

    LISTEN  //服务器在等待进入呼叫

    15

    SYN_RECV  //一个连接请求已经到达,等待确认

    16

    SYN_SENT  //应用已经开始,打开一个连接

    17

    ESTABLISHED  //正常数据传输状态/当前并发连接数

    18

    FIN_WAIT1  //应用说它已经完成

    19

    FIN_WAIT2  //另一边已同意释放

    20

    ITMED_WAIT  //等待所有分组死掉

    21

    CLOSING  //两边同时尝试关闭

    22

    TIME_WAIT  //另一边已初始化一个释放

    23

    LAST_ACK  //等待所有分组死掉

  • 相关阅读:
    监控里的主码流和子码流是什么意思
    监控硬盘容量计算
    一个能让你了解所有函数调用顺序的Android库
    电工选线
    oracle linux dtrace
    list all of the Oracle 12c hidden undocumented parameters
    Oracle Extended Tracing
    window 驱动开发
    win7 x64 dtrace
    How to Use Dtrace Tracing Ruby Executing
  • 原文地址:https://www.cnblogs.com/www886/p/4228356.html
Copyright © 2011-2022 走看看