johnnian/Blog

开发工具系列之—GoAcess:Nginx日志分析利器

johnnian opened this issue · 0 comments

Nginx日志分析工具—GoAcess

1、安装方法

安装方法参考: https://goaccess.io/download

在MacOS下安装比较简单:

brew install goaccess

2、基础使用方法

步骤1: Nginx需要开启访问日志,格式如下:

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for" "$request_body"';

步骤2: GoAcess的配置文件

➜  vi goaccess.conf

time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"

步骤3: 具体分析Nginx日志,并且查看结果

➜  goaccess -a -d -f ./nginx.log -p ./goaccess.conf -o ./out.html  --hour-spec=min --date-spec=hr --date-spec=hr

具体的页面如下:

WX20190723-111734@2x

每个模块的说明,可以参考:https://goaccess.io/man#description

3、参考