使用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

相關文章
相關標籤/搜索