|
|
第1行: |
第1行: |
| | | |
− | =查看nginx并发连接数(访问量)= | + | =see also= |
| + | [http://www.cnblogs.com/peida/archive/2013/01/08/2850483.html 每天一个linux命令(50):crontab命令] |
| | | |
− | ==No0 80端口网络连接数==
| + | [[category:ops]] |
− | <pre> # netstat -tan |awk '$4~/:80$/{++state[$NF]} END {for (key in state) print key,"\t",state[key]}'</pre>
| |
− | | |
− | ==No1、通过命令查看 ==
| |
− | <pre>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 //等待所有分组死掉
| |
− | </pre>
| |
− |
| |
− | ==No2、通过浏览器查看 ==
| |
− | <pre>通过web界面查看时Nginx需要开启status模块,也就是安装Nginx时加上 --with-http_stub_status_module 然后配置Nginx.conf,在server点里面加入如下内容
| |
− | location /status {
| |
− | stub_status on;
| |
− | access_log /usr/local/nginx/logs/status.log;
| |
− | auth_basic "NginxStatus"; }
| |
− | | |
− | 配置完后重新启动Nginx后我们可以通过浏览器访问http://localhost/status 查看,
| |
− | | |
− | 解析:
| |
− | Active connections //当前 Nginx 正处理的活动连接数。
| |
− | server accepts handled requests //总共处理了8 个连接 , 成功创建 8 次握手,总共处理了500个请求。
| |
− | Reading //nginx 读取到客户端的 Header 信息数。
| |
− | Writing //nginx 返回给客户端的 Header 信息数。
| |
− | Waiting //开启 keep-alive 的情况下,这个值等于 active - (reading + writing),意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接</pre>
| |
− | | |
− | ==2.访问量统计==
| |
− | <pre>
| |
− | 1.根据访问IP统计UV
| |
− | awk '{print $1}' access.log|sort | uniq -c |wc -l
| |
− | | |
− | 2.统计访问URL统计PV
| |
− | awk '{print $7}' access.log|wc -l
| |
− | | |
− | 3.查询访问最频繁的URL
| |
− | awk '{print $7}' access.log|sort | uniq -c |sort -n -k 1 -r|more
| |
− | | |
− | 4.查询访问最频繁的IP
| |
− | awk '{print $1}' access.log|sort | uniq -c |sort -n -k 1 -r|more
| |
− | | |
− | 5.根据时间段统计查看日志
| |
− | cat access.log| sed -n '/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p'|more
| |
− | </pre>
| |
− | =参考=
| |
− | [http://imork.blog.51cto.com/11642843/1883993 如何查看nginx状态(cat zabbix)?如何统计访问量?]
| |
− | [http://renxiangzyq.iteye.com/blog/675349 nginx 查看 并发连接数]
| |
− | | |
− | [[category:nginx]]
| |