linux nginx 监控,ngxtop - 在Linux中实时监控Nginx日志文件

ngxtop是一款免费开源,简单,灵活,完全可配置且易于使用的实时顶级监控工具,用于nginx服务器。 它通过解析nginx访问日志(默认位置始终为/var/log/nginx/access.log )来收集数据,并显示nginx服务器的有用指标,从而帮助您实时监控Web服务器。 它还允许您从远程服务器解析Apache日志。

如何在Linux中安装和使用Ngxtop

要安装ngxtop ,首先需要在Linux中安装PIP ,一旦您的系统上安装了pip ,就可以使用以下命令安装ngxtop 。$ sudo pip install ngxtop

监控Nginx服务器请求

现在你已经安装了ngxtop ,运行它的最简单方法是没有任何参数。 这将解析/var/log/nginx/access.log,并在后续模式下运行(在写入访问日志时注意新行)。$ sudo ngxtop

示例输出running for 411 seconds, 64332 records processed: 156.60 req/sec

Summary:

| count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |

|---------+------------------+-------+-------+-------+-------|

| 64332 | 2775.251 | 61262 | 2994 | 71 | 5 |

Detailed:

| request_path | count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |

|------------------------------------------+---------+------------------+-------+-------+-------+-------|

| /abc/xyz/xxxx | 20946 | 434.693 | 20935 | 0 | 11 | 0 |

| /xxxxx.json | 5633 | 1483.723 | 5633 | 0 | 0 | 0 |

| /xxxxx/xxx/xxxxxxxxxxxxx | 3629 | 6835.499 | 3626 | 0 | 3 | 0 |

| /xxxxx/xxx/xxxxxxxx | 3627 | 15971.885 | 3623 | 0 | 4 | 0 |

| /xxxxx/xxx/xxxxxxx | 3624 | 7830.236 | 3621 | 0 | 3 | 0 |

| /static/js/minified/utils.min.js | 3031 | 1781.155 | 2104 | 927 | 0 | 0 |

| /static/js/minified/xxxxxxx.min.v1.js | 2889 | 2210.235 | 2068 | 821 | 0 | 0 |

| /static/tracking/js/xxxxxxxx.js | 2594 | 1325.681 | 1927 | 667 | 0 | 0 |

| /xxxxx/xxx.html | 2521 | 573.597 | 2520 | 0 | 1 | 0 |

| /xxxxx/xxxx.json | 1840 | 800.542 | 1839 | 0 | 1 | 0 |

要退出,请按[Ctrl + C] 。

解析不同的访问日志

您可以使用-l标志解析不同的访问日志,例如特定的网站或Web应用程序,如图所示。$ sudo ngxtop -l /var/log/nginx/site1/access.log

列出客户的主要来源IP

以下命令将列出所有访问该站点的客户端的最大源IP。$ sudo top remote_addr -l /var/log/nginx/site1/access.log

示例输出running for 20 seconds, 3215 records processed: 159.62 req/sec

top remote_addr

| remote_addr | count |

|-----------------+---------|

| 118.173.177.161 | 20 |

| 110.78.145.3 | 16 |

| 171.7.153.7 | 16 |

| 180.183.67.155 | 16 |

| 183.89.65.9 | 16 |

| 202.28.182.5 | 16 |

| 1.47.170.12 | 15 |

| 119.46.184.2 | 15 |

| 125.26.135.219 | 15 |

| 125.26.213.203 | 15 |

使用特定的日志格式

要使用log_format指令中指定的日志格式,请使用-f选项,如图所示。$ sudo ngxtop -f main -l /var/log/nginx/site1/access.log

从远程服务器解析Apache日志

要使用通用格式从远程服务器解析Apache日志文件,请使用类似于以下的命令(指定您的用户名和远程服务器IP)。$ ssh [email protected]_server tail -f /var/log/apache2/access.log | ngxtop -f common

示例输出running for 20 seconds, 1068 records processed: 53.01 req/sec

Summary:

| count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |

|---------+------------------+-------+-------+-------+-------|

| 1068 | 28026.763 | 1029 | 20 | 19 | 0 |

Detailed:

| request_path | count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |

|------------------------------------------+---------+------------------+-------+-------+-------+-------|

| /xxxxxxxxxx | 199 | 55150.402 | 199 | 0 | 0 | 0 |

| /xxxxxxxx/xxxxx | 167 | 47591.826 | 167 | 0 | 0 | 0 |

| /xxxxxxxxxxxxx/xxxxxx | 25 | 7432.200 | 25 | 0 | 0 | 0 |

| /xxxx/xxxxx/x/xxxxxxxxxxxxx/xxxxxxx | 22 | 698.727 | 22 | 0 | 0 | 0 |

| /xxxx/xxxxx/x/xxxxxxxxxxxxx/xxxxxx | 19 | 7431.632 | 19 | 0 | 0 | 0 |

| /xxxxx/xxxxx/ | 18 | 7840.889 | 18 | 0 | 0 | 0 |

| /xxxxxxxx/xxxxxxxxxxxxxxxxx | 15 | 7356.000 | 15 | 0 | 0 | 0 |

| /xxxxxxxxxxx/xxxxxxxx | 15 | 9978.800 | 15 | 0 | 0 | 0 |

| /xxxxx/ | 14 | 0.000 | 0 | 14 | 0 | 0 |

| /xxxxxxxxxx/xxxxxxxx/xxxxx | 13 | 20530.154 | 13 | 0 | 0 | 0 |

有关更多使用选项,请使用以下命令查看ngxtop帮助消息。$ ngxtop -h

这就是现在! 在本文中,我们已经解释了如何在Linux系统中安装和使用ngxtop。 如果您有任何问题或想要添加到本指南的其他想法,请使用下面的评论表单。 另外,如果您遇到过类似的工具,请告诉我们,我们将不胜感激。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值