• GoAccess 分析 Nginx 日志


    0x00 事件

    帮助朋友搭建了博客,运行过了一段时间,准备发个网站分析报告给他。
    有效的数据只有 Nginx 的访问日志,于是使用决定 GoAccess 工具对这个日志进行分析,

    0x01 安装

    吾使用的是 CentOS,使用 yum 源进行安装即可。

    $ yum -y install goaccess
    

    其他平台可参考官方下载:https://goaccess.io/download

    0x02 使用

    1、确定日志格式
    从 Nginx 的配置中可以查看日志文件的格式:

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    

    日志文件内容:

    223.104.189.167 - - [07/Aug/2019:03:03:02 +0000] "GET /favicon.ico HTTP/1.1" 200 5 "https://www.example.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
    

    2、使用命令并加上格式化参数

    $ goaccess -f access.log --log-format='%h %^ %^[%d:%t +0000] "%r" %s  %b "%R" "%u"' --date-format='%d/%b/%Y' --time-format='%H:%M:%S'  -d -a > test.html
    $ ls
    access.log test.html
    

    参数说明:

    -f 
    指定输入日志文件的路径。
    --log-format 
    指定日志格式字符串。
    --date-format 
    日志格式日期。它们都以百分号(%)开头。
    --time-format 
    日志格式时间。它们都以百分比(%)开头。
    -a 
    按主机启用用户代理列表。
    -d 
    在HTML或JSON输出上启用IP解析器。
    

    格式化参数主要为日志格式化 --log-format、日期格式化 --date-format 和时间格式化 --time-format
    https://goaccess.io/man#custom-log 可以查找 %* 对应的说明符

    3、查看分析文件

    最后在浏览器中打开 test.html 文件,就能看到访问日志的具体分析:

  • 相关阅读:
    雷林鹏分享:Lua 运算符
    雷林鹏分享:PHP JSON
    不要提交代码到HEAD上
    Mr Cao 的提问
    使用masory
    git 下载单个文件 已经添加多个远程服务器
    自动生产jason的工具
    简单的应用可以用storyBoard
    《创业维艰》
    造成死锁的各种情况
  • 原文地址:https://www.cnblogs.com/nnylee/p/11359211.html
Copyright © 2020-2023  润新知