ngxtop(nginx实时监控工具)
ngxtop(nginx实时监控工具)
安装 ngxtop
yum -y install python-pip(如当前yum源不能找到python-pip,则新增扩展的epel-release扩展源:yum -y install epel-release)
pip install ngxtop(如安装有问题:则 yum install python-setuptools)
使用ngxtop
1、
监控当前所指定的nginx的实时状态(根据nginx.conf来进行指定所要监控的nginx信息,需注意:nginx.conf中所配置的日志产生路径必须是绝对路径,因为ngxtop是要找到对应的日志文件来进行分析而给出的实时结果)
ngxtop -c /app/nginx-web1/conf/nginx.conf(默认展示10条信息,或者使用 -n 来指定所要实现的行数,-n 20 表示显示20行)

如上所示:
其中 74 seconds,表示当前已经监控的时长,单位秒;
Summary:显示所有的统计后总结信息;
Detailed则展示的是所有的请求明细:request_path 表示当前所请求的路径,count 请求的次数,avg_bytes_send 当前请求所返回的字节,2XX 表示当前请求的返回状态(200等),3xx,4xx,5xx 等均表示当前请求路径的状态码;
2、
设置只实时显示,20个最频繁的请求;
ngxtop -c /app/nginx-web1/conf/nginx.conf -n 20
3、
实时 统计被请求最多的客户端IP地址 remote_addr;以及统计各请求status状态的数量 status;以及统计各请求在对应的时间段的请求数量,time_local
ngxtop -c /app/nginx-web1/conf/nginx.conf -n 20 top remote_addr status time_local

OK,看完上述两个使用方式后,接下来将会说明,ngxtop 的语法格式,和各个参数的意义;这样在后续的使用中,就可以随心所欲定制符合自身统计要求的实时展示了;
NGXTOP的用法格式如下:
语法如下:
1、ngxtop [options]
2、ngxtop [options](备注:参数) (print|top|avg|sum)(备注:内含的4个关键词) <var>(备注:所要使用的变量:其中ngxtop内置的变量有bodybytessend,http_referer,httpuseragent,remote_addr,remote_user,request,status,time_local)
其中print 表示自定义显示的变量信息,如:ngxtop print remote_addr status http_referer(表示只实时输出显示,remote_addr(表示客户端请求IP),status等信息)
top 表示
3、ngxtop info
所对应的可选参数分别如下所示:
Options:
-l <file>, --access-log <file> access log file to parse.
-f <format>, --log-format <format> log format as specify in log_format directive.
--no-follow ngxtop default behavior is to ignore current lines in log
and only watch for new lines as they are written to the access log.
Use this flag to tell ngxtop to process the current content of the access log instead.
-t <seconds>, --interval <seconds> report interval when running in follow mode [default: 2.0]
-g <var>, --group-by <var> group by variable [default: request_path]
-w <var>, --having <expr> having clause [default: 1]
-o <var>, --order-by <var> order of output for default query [default: count]
-n <number>, --limit <number> limit the number of records included in report for top command [default: 10]
-a <exp> ..., --a <exp> ... add exp (must be aggregation exp: sum, avg, min, max, etc.) into output
-v, --verbose more verbose output
-d, --debug print every line and parsed record
-h, --help print this help message.
--version print version information.
Advanced / experimental options:
-c <file>, --config <file> allow ngxtop to parse nginx config file for log format and location.
-i <filter-expression>, --filter <filter-expression> filter in, records satisfied given expression are processed.
-p <filter-expression>, --pre-filter <filter-expression> in-filter expression to check in pre-parsing phase.
可参考链接:


【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端