goaccess分析json格式日志

一.安装使用yum安装,yum install goaccess

二.主要介绍格式问题

1.nginx日志格式如下:

log_format main escape=json '{"time_local":"$time_local",'

'"remote_addr":"$remote_addr",'

'"referer":"$http_referer",'

'"request":"$request",'

'"status":"$status",'

'"bytes":"$body_bytes_sent",'

'"agent":"$http_user_agent",'

'"dm":"$request_body",'

'"up_resp_time":"$upstream_response_time",'

'"request_time":"$request_time"'

'}';

2.nginx输出日志内容:

{"time_local":"11/Jul/2024:10:56:30 +0800","remote_addr":"x.x.x.x","referer":"https://www.xxxxx","request":"GET /xxxx/xxx/xxxx HTTP/2.0","status":"200","bytes":"47","agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)","dm":"","up_resp_time":"","request_time":"0.000"}

3.goaccess配置如下:

goaccess -f access.log -o /data/java-program/webpage/record.html --real-time-html --log-format='"time_local":" %d:%t %^","%^":"%h","%^":"%R","%^":"%U","%^":"%s",%^,%^,%^,%^,"%^":"%T"' --time-format='%H:%M:%S' --date-format='%d/%b/%Y'

三.遇到的问题

1.时间格式问题

"time_local":" %d:%t %^"

注意中间这里有个空格,不加这个空格会报Token '[11/Jul/2024' doesn't match specifier '%d' ,

下面这种方法无法解决不识别问题,或者我没试出来。

复制代码
LANG="en_US.UTF-8" bash -c 'goaccess access.log'

日志输出之后中间并没有这个空格,在解析日志的时候是出现了"双引号,去掉双引号之后依然无法识别,后偶然间加了空格,成功识别,希望踩坑经过可以帮助后来的人。

2.log-format格式问题

这个里面的格式要和输出的日志保持一致,里面空格也需要添加才能识别到,所以遇到空格多又不是特别重要的,可以使用%^跳过。

3.time-format,date-format

这两个必须要指定,不然会出现时间格式未设置的问题,参考命令设置。

相关推荐
Rain的Java大神之路5 小时前
JavaWeb开发如何解决跨域问题
java·前端·后端·nginx·web安全·面试·运维开发
Lsetea10 小时前
Nginx报SSL_CTX_use_PrivateKey failed:证书与私钥不匹配怎么排查
nginx·https·ssl证书·openssl·私钥
!chen12 小时前
客户环境 Nginx 配置流式报表与超时排查
运维·nginx
大喵桑丶14 小时前
AlmaLinux 9 上基于 PostgreSQL + Nginx 部署高可用轻量级 Gitea 服务
nginx·postgresql·gitea
我最爱吃鱼香茄子2 天前
【踩坑实录】若依Vue宝塔部署:验证码空白、反复提示登录状态已过期|完整排错
nginx·宝塔·若依·ruoyi‑vue·登录状态已过期
dazhong20122 天前
Docker 进阶篇(二) Docker Compose 部署 Nginx 实践
nginx·docker·容器
笑梦无境2 天前
nginx安装(5)
linux·运维·nginx
墨着染霜华2 天前
SpringCloud Gateway线上Nginx代理后自定义下划线请求头丢失(app_name/app_version获取不到)完美解决
nginx·spring cloud·gateway
流光D2 天前
AI Era: Building Web Sites and Configuring Nginx Reverse Proxy Process
前端·人工智能·nginx
Lsetea3 天前
Cloudflare报526 Invalid SSL certificate:源站证书与Nginx回源TLS排查
nginx·https·ssl证书·cloudflare·tls