使用 GoAccess 分析 JSON 格式的 Nginx 日志

GoAccess 是一款强大的命令行工具,可以用于分析 Nginx 日志。对于以 JSON 格式记录的 Nginx 日志,我们可以使用 GoAccess 的 --log-format=JSON 选项进行分析。

示例 JSON 日志记录:

{  "@timestamp":"2023-04-23T16:52:06+08:00",  "host":"10.0.0.4",  "clientip":"58.32.238.44",  "remote_user":"-",  "request":"GET /wms/rf/pick/pref HTTP/1.1",  "http_user_agent":"okhttp/4.5.0",  "size":762,  "responsetime":0.008,  "uct":0.001,  "uht":0.008 ,  "upstreamtime":"0.008",  "upstreamhost":"10.0.0.4:6001",  "http_host":"rmwms.pepsichina.cn",  "url":"/wms/rf/pick/pref",  "domain":"rmwms.pepsichina.cn",  "xff":"-",  "referer":"-",  "status":"200",  "connection_upgrade":"close",  "http_upgrade", "-"
}

GoAccess 命令:

goaccess -f /var/log/nginx/access.log --log-format=JSON --date-format=%Y-%m-%dT%H:%M:%S%z

参数说明:

  • -f /var/log/nginx/access.log: 指定 Nginx 日志文件路径。
  • --log-format=JSON: 指示 GoAccess 使用 JSON 格式解析日志。
  • --date-format=%Y-%m-%dT%H:%M:%S%z: 指定日志中日期和时间的格式。

注意:

  • --log-format=JSON 选项仅适用于 GoAccess 1.5 及以上版本。
  • 具体的 GoAccess 命令参数和选项可以参考 GoAccess 的官方文档。
使用 GoAccess 分析 JSON 格式的 Nginx 日志

原文地址: https://www.cveoy.top/t/topic/nFZP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录