ngxtop 使用指南

2017-03-29

ngxtop 是一个纯 python 实时分析 nginx 访问日志的 python 项目,并且支持 python3

安装


pip install ngxtop

默认输出:


~# ngxtop
running for 548 seconds, 196 records processed: 0.36 req/sec

Summary:
|   count |   avg_bytes_sent |   2xx |   3xx |   4xx |   5xx |
|---------+------------------+-------+-------+-------+-------|
|     196 |         4189.750 |   183 |     3 |     9 |     1 |

Detailed:
| request_path                                   |   count |   avg_bytes_sent |   2xx |   3xx |   4xx |   5xx |
|------------------------------------------------+---------+------------------+-------+-------+-------+-------|
| /admin/jsi18n/                                 |      16 |         2191.000 |    16 |     0 |     0 |     0 |
| /admin/weixin/article/                         |      16 |         7133.188 |    16 |     0 |     0 |     0 |
| /jet/jsi18n/                                   |      14 |         2191.000 |    14 |     0 |     0 |     0 |
| /tags/%E5%A8%B1%E4%B9%90                       |      10 |        12220.100 |    10 |     0 |     0 |     0 |
| /                                              |       5 |          652.200 |     4 |     0 |     1 |     0 |
| /admin/articles/article/                       |       5 |         7822.000 |     5 |     0 |     0 |     0 |
| /admin/articles/article/64352/                 |       2 |        15374.000 |     2 |     0 |     0 |     0 |
| /api/articles/06549522408f4603f278e1f76327d5dc |       2 |            0.000 |     2 |     0 |     0 |     0 |
| /api/articles/49fc7a754153b414677cd3bb32b2225d |       2 |            0.000 |     2 |     0 |     0 |     0 |
| /tags/%E6%AE%B5%E5%AD%90                       |       2 |        11734.000 |     2 |     0 |     0 |     0 |

查看和统计用户访问的ip


~#ngxtop top remote_addr
running for 236 seconds, 90 records processed: 0.38 req/sec

top remote_addr
| remote_addr    |   count |
|----------------+---------|
| 66.249.79.126  |      37 |
| 124.79.41.152  |      32 |
| 66.249.79.49   |      11 |
| 66.249.79.53   |       2 |
| 66.249.79.57   |       2 |
| 106.47.172.123 |       1 |

统计下当前有多少4xx和5xx的请求


~# ngxtop -i 'status >= 400' print request status http_referer
running for 320 seconds, 9 records processed: 0.03 req/sec

request, status, http_referer:
| request                                                      |   status | http_referer   |
|--------------------------------------------------------------+----------+----------------|
| GET /articles/chun-jie-ying-yuan-da-pian-zhe HTTP/1.1        |      404 | -              |
| GET /articles/dang-wo-men-zai-tan-lun-ju-can HTTP/1.1        |      404 | -              |
| GET /articles/jin-nian-zui-hao-kan-de-10ben HTTP/1.1         |      404 | -              |
| GET /articles/pi-gu-da-shi-shi-yao-ti-yan/ HTTP/1.1          |      404 | -              |
| GET /articles/sui-ran-wo-jing-chang-jiao-cuo HTTP/1.1        |      404 | -              |
| GET /articles/xin-dian-gun-muji-yi-zhu-zong HTTP/1.1         |      404 | -              |
| GET /articles/zhong-yu-deng-dao-zhe-bu-shen HTTP/1.1         |      404 | -              |

写在最后:

可能这个小工具对你并没有神马卵用。 但是,对于在阿里云上购买了一台服务器,又没有神马钱的小伙伴也许有点小帮助吧

相关文档