如何查看Web效劳器并发恳求衔接数

1、查看Web效劳器(Nginx Apache)的并发恳求数及其TCP衔接状态:

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

netstat -n|grep  ^tcp|awk \'{print $NF}\'|sort -nr|uniq -c

或者:

netstat -n | awk \'/^tcp/ {++state[$NF]} END {for(key in state) print key,\"t\",state[key]}\'

返回结果普通如下:

LAST_ACK 5 (正在等候处置的恳求数)

SYN_RECV 30 connecting: http://www.metabase.cn/ time out :25s

SYN_RECV 30 connecting: http://www.jinanwuliangye.com time out :25s

SYN_RECV 30 connecting: http://www.tongxinglong.com/ time out :25s

SYN_RECV 30 connecting: http://www.qclchina.com/ time out :25s

SYN_RECV 30 connecting: http://www.vipfuxin.com/ time out :25s

SYN_RECV 30 connecting: http://www.minnan888.net/ time out :25s

SYN_RECV 30 connecting: http://www.lcsyt.com/ time out :25s

SYN_RECV 30 connecting: http://lf.yunnanw.cn time out :25s

SYN_RECV 30 connecting: http://www.ceocbs.com/ time out :25s

SYN_RECV 30 connecting: http://www.yzbljp.com/ time out :25s

SYN_RECV 30 connecting: http://www.hyyfscl.com/ time out :25s

SYN_RECV 30 connecting: http://www.shoudashou.com/ time out :25s

SYN_RECV 30 connecting: http://www.shuoma.com.cn/ time out :25s


ESTABLISHED 1597 (正常数据传输状态)

FIN_WAIT1 51

FIN_WAIT2 504

TIME_WAIT 1057 (处置终了,等候超时完毕的恳求数)

其他参数阐明:

CLOSED:无衔接是活动的或正在停止

LISTEN:效劳器在等候进入呼叫

SYN_RECV:一个衔接恳求曾经抵达,等候确认

SYN_SENT:应用曾经开端,翻开一个衔接

ESTABLISHED:正常数据传输状态

FIN_WAIT1:应用说它曾经完成

FIN_WAIT2:另一边已同意释放

ITMED_WAIT:等候一切分组死掉

CLOSING:两边同时尝试关闭

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

LAST_ACK:等候一切分组死掉

2、查看Nginx运转进程数

ps -ef | grep nginx | wc -l

返回的数字就是nginx的运转进程数,假如是apache则执行

ps -ef | grep httpd | wc -l

3、查看Web效劳器进程衔接数:

netstat -antp | grep 80 | grep ESTABLISHED -c

4、查看MySQL进程衔接数:

ps -axef | grep mysqld -c