快速的Web访问日志分析工具

HTML报表截图

语法

goaccess -f log [-c][-r][-m][-h][-q][-d][-g][-a][-o csv|json][-e IP_ADDRESS][...]

依赖库

Distro

NCurses GLib >= 2.0.0 GeoIP (optional) Tokyo Cabinet (optional)

Ubuntu/Debian

libncursesw5-dev libglib2.0-dev libgeoip-dev libtokyocabinet-dev

Fedora/RHEL/CentOS

ncurses-devel glib2-devel geoip-devel tokyocabinet-devel

Arch Linux

ncurses glib2 geoip compile from source

Gentoo

sys-libs/ncurses dev-libs/glib:2 dev-libs/geoip dev-db/tokyocabinet

GitHub安装方法

$ git clone https://github.com/HackingLab/GoaccessCN.git
$ cd GoaccessCN
$ ./configure --enable-geoip --enable-utf8
$ make
$ sudo make install

配置选项说明

使用命令: ./configure --help可以查看帮助
--enable-debug Compile with debugging symbols and turn off compiler optimizations.
--enable-utf8 Compile with wide character support. Ncursesw is required.
--enable-geoip 打开地理位置支持,需要安装GeoIP库
--enable-tcb=<memhash|btree> Compile with Tokyo Cabinet storage support. memhash will utilize Tokyo Cabinet's on-memory hash database. btree will utilize Tokyo Cabinet's on-disk B+ Tree database.
--disable-zlib 关闭B+树数据库的zlib压缩
--disable-bzip 关闭B+树的bzip2压缩

使用方法

指定配置文件(HTML)

goaccess -f 'access_log' -p ./goaccess.conf -a >~/test.html

不指定配置文件(HTML)

goaccess -f access.log -a > report.html

JSON格式输出(不支持中文)

goaccess -f access.log -a -d -o json > report.json

JSON格式输出(不支持中文)

goaccess -f access.log -o csv > report.csv

自定义日志格式

log_format The log_format variable followed by a space or \t for tab-delimited, specifies the log format string.

%x A date and time field matching the timeformat and dateformat variables. This is used when a timestamp is given instead of the date and time being in two separated variables.

%t time field matching the time_format variable.

%d date field matching the date_format variable.

%h host (the client IP address, either IPv4 or IPv6)

%r The request line from the client. This requires specific delimiters around the request (as single quotes, double quotes, or anything else) to be parsable. If not, we have to use a combination of special format specifiers as %m %U %H.

%m The request method.

%U The URL path requested (including any query string).

%H The request protocol.

%s The status code that the server sends back to the client.

%b The size of the object returned to the client.

%R The Referer HTTP request header.

%u The user-agent HTTP request header.

%D The time taken to serve the request, in microseconds.

%T The time taken to serve the request, in seconds with milliseconds resolution.

%L The time taken to serve the request, in milliseconds as a decimal number.

%^ Ignore this field.

GoAccess 日志中必须具备的几个字段

a valid IPv4/6 %h
a valid date %d
the request %r

其他说明请参考官方文档

官方文档