使用goaccess解析nginx日志

因为我指定了安装路径为/usr/local/goaccesshtml

所以运行主程序在该路径的bin目录下,配置文件在etc下nginx

 

使用方法:服务器

直接解析代理

在nginx日志目录下运行日志

/usr/local/goaccess/bin/goaccess -f access.logorm

 

或是输出html文件server

/usr/local/goaccess/bin/goaccess -f access.log -a > test.htmlhtm

 

然而实际使用过程当中一直报错:ip

Fatal error has occurred
Error occured at: src/goaccess.c - main - 1230
Nothing valid to process. Verify your date/time/log format.rem

 

缘由是所使用的nginx的日志通过定制,并非经常使用的日志格式,所以须要根据nginx日志格式修改goaccess的日志解析配置。

这是nginx中当前所使用的日志配置:

[$time_local] - $server_name - $remote_addr - $upstream_addr - $remote_user - "$request" $status $upstream_status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time $request_time

据此修改goaccess配置文件/usr/local/goaccess/etc/goaccess.conf

添加日志配置:

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

说明:

date-format日期格式中,%d为天、%b为月份缩写、%Y为年

time-format时间格式中,%H、%M、%S分别为时、分、秒

log-format日志格式中,%d为引用日期格式配置、%t为引用日期格式配置、%^为忽略该项、%v为服务器名、%h为远端ip地址、%r为实际请求、%s为请求返回状态、%b为请求大小、%R为http referer头 、%u为http用户代理、%T为响应时间

 

要注意如下几点:

一、log-format中必需要有 %d、%h、%r

二、格式要一一对应

三、不能有重复的项

 

附goaccess在线手册:

https://goaccess.io/man#custom-log

相关文章
相关标签/搜索