Linux 下Web服务器 Nginx 状态监控 查看nginx当前并发 连接 请求状态 图文教程

nginx和php-fpm一样内建了一个状态页,对于想了解nginx的状态以及监控nginx非常有帮助。可以用网页的形式查看nginx服务器的连接数、请求数等情况。

  • Nginx Status模块:

1. 启用nginx status配置

通过web界面查看时Nginx需要开启status模块,也就是安装Nginx时加上-–with-http_stub_status_module。如果已安装好nginx,可以通过下面命令来查看安装了哪些模块。

nginx -V

nginx version: nginx/1.10.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –modules-path=/usr/lib64/nginx/modules –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=nginx –group=nginx –with-http_ssl_module –with-http_realip_module –with-http_addition_module –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_stub_status_module –with-http_auth_request_module –with-http_xslt_module=dynamic –with-http_image_filter_module=dynamic –with-http_geoip_module=dynamic –with-http_perl_module=dynamic –add-dynamic-module=njs-1c50334fbea6/nginx –with-threads –with-stream –with-stream_ssl_module –with-http_slice_module –with-mail –with-mail_ssl_module –with-file-aio –with-ipv6 –with-http_v2_module –with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic’

Linux 下Web服务器 Nginx 状态监控 查看nginx当前并发 连接 请求状态 图文教程

然后在默认主机里面加上location或者你希望能访问到的主机里面。

server {
    listen *:80 default_server;
    server_name *.abc11524.sg-host.com abc11524.sg-host.com;
    location /ngx_status {
        stub_status on;
        access_log off;
        #allow 127.0.0.1;
        #deny all;
    }
}

2. 重启nginx

请依照你的环境重启你的nginx

service nginx restart

3. 打开status页面

curl http://127.0.0.1/ngx_status

Active connections: 11921 server accepts handled requests ?11989 11989 11991 Reading: 0 Writing: 7 Waiting: 42   或者使用浏览器打开:

Linux 下Web服务器 Nginx 状态监控 查看nginx当前并发 连接 请求状态 图文教程

4. nginx status详解

active connections – 活跃的连接数量
server accepts handled requests — 总共处理了11989个连接 , 成功创建11989次握手, 总共处理了11991个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

  • 命令行模式查看:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
Linux 下Web服务器 Nginx 状态监控 查看nginx当前并发 连接 请求状态 图文教程

TIME_WAIT 17
ESTABLISHED 3254
LAST_ACK 236
FIN_WAIT_1 648
FIN_WAIT_2 581
CLOSING 7
CLOSE_WAIT 4916

解析:
CLOSED? //无连接是活动的或正在进行
LISTEN? //服务器在等待进入呼叫
SYN_RECV? //一个连接请求已经到达,等待确认
SYN_SENT? //应用已经开始,打开一个连接
ESTABLISHED? //正常数据传输状态/当前并发连接数
FIN_WAIT1? //应用说它已经完成
FIN_WAIT2? //另一边已同意释放
ITMED_WAIT? //等待所有分组死掉
CLOSING? //两边同时尝试关闭
TIME_WAIT? //另一边已初始化一个释放
LAST_ACK? //等待所有分组死掉

链接到文章: https://vpsum.com/42193.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注