nginx状态监控
通过查看nginx的并发连接,我们可以更清除的知道网站的负载情况。nginx并发查看有两种方法(之所以这么说,是因为笔者只知道两种),一种是通过web界面,一种是通过命令,web查看要比命令查看显示的结果精确一些。下面介绍这两种查看方法
no1、通过浏览器查看
通过web界面查看时nginx需要开启status模块,也就是安装nginx时加上 –with-http_stub_status_module 然后配置nginx.conf,在server点里面加入如下内容
location /nginx_status { stub_status on; access_log off; allow 192.168.1.100; 访问ip deny all; }
配置完后重新启动nginx后我们可以通过浏览器访问http://localhost/status 查看,如下图
650) this.width=650; border=0 alt= src=http://cdn.verydemo.com/upload/2013_04_05/13651301539440.jpg>
解析:
active connections //当前 nginx 正处理的活动连接数。
server accepts handledrequests //总共处理了8 个连接 , 成功创建 8 次握手,总共处理了500个请求。
reading //nginx 读取到客户端的 header 信息数。
writing //nginx 返回给客户端的 header 信息数。
waiting //开启 keep-alive 的情况下,这个值等于 active – (reading + writing),意思就是 nginx 已经处理完正在等候下一次请求指令的驻留连接
no2、通过命令查看
#netstat -n | awk ‘/^tcp/ {++s[$nf]} end {for(a in s) print a, s[a]}’
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 //等待所有分组死掉
当你幸福的时候,我不在,当我幸福的时候,你也不在
