ngxtop 安装

安装pip
centos安装:
 
yum install python-pip
安装:
[root@VM_217_242_centos home]# pip install ngxtop  #执行
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Collecting ngxtop
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading ngxtop-0.0.2-py2.py3-none-any.whl
Collecting tabulate (from ngxtop)
  Downloading tabulate-0.7.7-py2.py3-none-any.whl
Collecting docopt (from ngxtop)
  Downloading docopt-0.6.2.tar.gz
Collecting pyparsing (from ngxtop)
  Downloading pyparsing-2.1.10-py2.py3-none-any.whl (56kB)
    100% |################################| 57kB 97kB/s 
Installing collected packages: tabulate, docopt, pyparsing, ngxtop
  Running setup.py install for docopt
Successfully installed docopt-0.6.2 ngxtop-0.0.2 pyparsing-2.1.10 tabulate-0.7.7
出现这个就是完成了
使用:
 
列出访问量前10的ip
ngxtop --no-follow --group-by remote_addr   #--no-follow是处理之前的日志不跟随现在的日志。
 
列出访问状态为502的请求和状态
 ngxtop --no-follow -i "status==502" print request status
ngxtop -i 'status == 404' print request status #只处理复合规则的记录
ngxtop -i "status >= 200" print request status
远程登录到另外的web机器。查看nginx的日志
ssh q1 tail -f /var/log/ngx-openresty/access.log |ngxtop
之前试过一次但是没有任何反映。在q1上装了ngxtop之后可以使用了。应该是有关系的。
再次执行:
ssh v1 tail -f /var/log/ngx-openresty/access.log | ngxtop
没检测几秒就闪退了。
开启debug
ssh v1 tail -f /var/log/ngx-openresty/access.log | ngxtop -d
 
 
 
 

ngxtop 使用

基本使用方法如下:

ngxtop [options]
ngxtop [options] (print|top|avg|sum) <var>
ngxtop info

这里是一些通用选项。

  • -l : 指定日志文件的完整路径 (Nginx 或 Apache2)
  • -f : 日志格式
  • --no-follow: 处理当前已经写入的日志文件,而不是实时处理新添加到日志文件的日志
  • -t : 更新频率
  • -n : 显示行号
  • -o : 排序规则(默认是访问计数)
  • -a ..., --a ...: 添加表达式(一般是聚合表达式如: sum, avg, min, max 等)到输出中。
  • -v: 输出详细信息
  • -i : 只处理符合规则的记录
  • -n <number>或 --limit <number> 显示top多条,默认前top 10条

以下是一些内置变量,他们的含义不言自明。

  • bodybytessend
  • http_referer
  • httpuseragent
  • remote_addr
  • remote_user
  • request
  • status
  • time_local

使用 ngxtop 监控 Nginx

ngxtop 默认会从其配置文件 (/etc/nginx/nginx.conf) 中查找 Nginx 日志的地址。所以,监控 Nginx ,运行以下命令即可:

$ ngxtop

这将会列出10个 Nginx 服务,按请求数量排序。

显示前20个最频繁的请求:

$ ngxtop -n 20

获取Nginx基本信息:

$ ngxtop info

你可以自定义显示的变量,简单列出需要显示的变量。使用 "print" 命令显示自定义请求。

$ ngxtop print request http_user_agent remote_addr

显示请求最多的客户端IP地址

$ ngxtop top remote_addr

显示状态码是404的请求

$ ngxtop -i 'status == 404' print request status

除了Nginx,ngtop 还可以处理其他的日志文件,比如 Apache 的访问文件。使用以下命令监控 Apache 服务器:

$ tail -f /var/log/apache2/access.log | ngxtop -f common
 

 

转载于:https://www.cnblogs.com/Lvjingjing/p/6272896.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值