ngxtop:在命令行实时监控 Nginx 的神器

转:https://www.phpsong.com/3391.html

ngxtop实时监控Nginx工具

 Nginx  2017-09-25 10:00:32  722浏览  0评论

今天在微信的公众号上推送的文章里看到介绍ngxtop的文章,感觉这个工具还是挺有用的, ngxtop 从界面和名称都借鉴了著名的top命令,ngxtop 是通过分析nginx的日志文件显示内容的,ngxtop是用python编写的一个工具

安装 ngxtop

安装pip

 
  1. yum -y install python-pip

安装ngxtop

 
  1. pip install ngxtop

ngxtop命令使用

 
  1. Usage:
  2. ngxtop [options]
  3. ngxtop [options] (print|top|avg|sum) <var> ...
  4. ngxtop info
  5. ngxtop [options] query <query> ...
  6.  
  7. Options:
  8. -l <file>, --access-log <file> access log file to parse.【选择日志文件】
  9. -f <format>, --log-format <format> log format as specify in log_format directive. [default: combined]
  10. --no-follow ngxtop default behavior is to ignore current lines in log【日志格式】
  11. and only watch for new lines as they are written to the access log.
  12. Use this flag to tell ngxtop to process the current content of the access log instead.【处理当前已经写入的日志文件,而不是实时处理新添加到日志文件的日志】
  13. -t <seconds>, --interval <seconds> report interval when running in follow mode [default: 2.0]【多少秒更新一次】
  14.  
  15. -g <var>, --group-by <var> group by variable [default: request_path]【类似于mysql分组】
  16. -w <var>, --having <expr> having clause [default: 1]【类似于mysql having
  17. -o <var>, --order-by <var> order of output for default query [default: count]【类似于mysql orderby 排序】
  18. -n <number>, --limit <number> limit the number of records included in report for top command [default: 10]【限制显示的行数】
  19. -a <exp> ..., --a <exp> ... add exp (must be aggregation exp: sum, avg, min, max, etc.) into output【添加表达式(一般是聚合表达式如: sum, avg, min, max 等)到输出中】
  20.  
  21. -v, --verbose more verbose output【详细信息】
  22. -d, --debug print every line and parsed record【调试】
  23. -h, --help print this help message.【帮助信息】
  24. --version print version information.【版本信息】
  25.  
  26. Advanced / experimental options:
  27. -c <file>, --config <file> allow ngxtop to parse nginx config file for log format and location.【配置文件中日志文件的格式】
  28. -i <filter-expression>, --filter <filter-expression> filter in, records satisfied given expression are processed.
  29. -p <filter-expression>, --pre-filter <filter-expression> in-filter expression to check in pre-parsing phase.
  30.  
  31. Examples:【下面是使用例子】
  32. All examples read nginx config file for access log location and format.
  33. If you want to specify the access log file and / or log format, use the -f and -a options.
  34.  
  35. "top" like view of nginx requests【类似于top命令】
  36. $ ngxtop
  37.  
  38. Top 10 requested path with status 404:【显示10404的请求】
  39. $ ngxtop top request_path --filter 'status == 404'
  40.  
  41. Top 10 requests with highest total bytes sent【显示10条最大流量的请求】
  42. $ ngxtop --order-by 'avg(bytes_sent) * count'
  43.  
  44. Top 10 remote address, e.g., who's hitting you the most【10个地址,可以知道谁在访问你,攻击你】
  45. $ ngxtop --group-by remote_addr
  46.  
  47. Print requests with 4xx or 5xx status, together with status and http referer【显示4XX和5XX的请求】
  48. $ ngxtop -i 'status >= 400' print request status http_referer
  49.  
  50. Average body bytes sent of 200 responses of requested path begin with 'foo':【foo开头200状态码的请求】
  51. $ ngxtop avg bytes_sent --filter 'status == 200 and request_path.startswith("foo")'
  52.  
  53. Analyze apache access log from remote machine using 'common' log format【统计apache日志】
  54. $ ssh remote tail -f /var/log/apache2/access.log | ngxtop -f common
  55.  

安装之后默认会自动识别nginx的日志,使用

 
  1. ngxtop info

ngxtop info

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值