yum -y install python-pip
pip install ngxtop
ngxtop使用参数
ngxtop 参数 print|top|avg|sum
ngxtop info 显示日志格式信息
-l
-f
--no-follow 处理以前的日志,实时日志不做处理
-t
-g 或 --group-by 按变量分组,默认显示 request_path
-w 或 --having
-o 或 --order-by 输出的排序方式,默认: 访问数
-n
-a
-v或 --verbose 详细输出
-d或 --debug debug模式,输出每行及记录
-h或 --help 显示帮助详细
--version 显示版本信息
高级参数
-c
-i
-p
另外一些变量可以在分析时用到,名字含义同日志格式里的设置:remote_addr、remote_user、time_local、request、request_path、status、body_bytes_sent、http_referer、http_user_agent。
二、Ngxtop使用实例 实时监控日志
[root@localhost ~]# ngxtop -l /usr/local/nginx/logs/access.log
日志分析
[root@localhost ~]# ngxtop -l /usr/local/nginx/logs/access.log --no-follow
按rquest_path且是404的前10请求:
[root@localhost ~]# ngxtop -l /usr/local/nginx/logs/access.log --no-follow top request_path --filter 'status == 404'
按总bytes sent最高的前10:
[root@localhost ~]# ngxtop -l /usr/local/nginx/logs/access.log --no-follow --order-by 'avg(bytes_sent) * count'
按remote address进行排序前10:
[root@localhost ~]# ngxtop -l /usr/local/nginx/logs/access.log --no-follow --group-by remote_addr
显示400或更高返回状态码的且只显示request、status、http_referer这三列信息:
[root@localhost ~]# ngxtop -l /usr/local/nginx/logs/access.log --no-follow -i 'status >= 400' print request status http_referer
显示bytes_sent平均值且状态码为200且request_path以www开始的前10:
[root@localhost ~]# ngxtop -l /usr/local/nginx/logs/access.log --no-follow avg bytes_sent --filter 'status == 200 and request_path.startswith("www")'
关于 ngxtop 的更多用法,可通过 ngxtop -h 查询。