1、GoAccess简介

GoAccess是一个非常良心的开源软件,它的良心之处体现在如下方面:

  1. 安装简单;
  2. 操作容易;
  3. 界面酷炫;

GoAccess 官网 https://goaccess.io
GoAccess日志分析工具 - 图1

2、安装GoAccess

2.1 系统环境说明

  1. [root@clsn.io /root]
  2. #cat /etc/redhat-release
  3. CentOS release 6.8 (Final)
  4. [root@clsn.io /root]
  5. #uname -a
  6. Linux clsn.io 4.10.5-1.el6.elrepo.x86_64 #1 SMP Wed Mar 22 14:55:33 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
  7. [root@clsn.io /root]
  8. #sestatus
  9. SELinux status: disabled

2.2 安装GoAccess

官网提供多种系统版本的安装方法: https://goaccess.io/download#installation

  1. $ wget https://tar.goaccess.io/goaccess-1.3.tar.gz
  2. $ tar -xzvf goaccess-1.3.tar.gz
  3. $ cd goaccess-1.3/
  4. $ ./configure --enable-utf8 --enable-geoip=legacy
  5. $ make
  6. # make install

配置完成的信息

  1. Your build configuration:
  2. Prefix : /usr/local
  3. Package : goaccess
  4. Version : 1.3
  5. Compiler flags : -pthread
  6. Linker flags : -lnsl -lncursesw -lGeoIP -lpthread
  7. Dynamic buffer : no
  8. Geolocation : GeoIP Legacy
  9. Storage method : In-memory Hash Database (Default)
  10. TLS/SSL : no
  11. Bugs : goaccess@prosoftcorp.com

2.3 使用GoAccess分析日志

注:本次分析日志为 nignx 标准输出日志

  1. [root@clsn.io /var/log/nginx] clsn.io Blog WebSite
  2. #goaccess -f clsn.io.log

日志格式选为 NCSA Combined Log Format
GoAccess日志分析工具 - 图2
回车即可看到当前日志分析结果
GoAccess日志分析工具 - 图3

3、生成HTML页面

3.1 修改配置

查看当前配置

  1. [root@clsn.io /usr/local/etc/goaccess] clsn.io Blog WebSite
  2. #egrep -v "^#|^$" goaccess.conf
  3. config-dialog false
  4. hl-header true
  5. json-pretty-print false
  6. no-color false
  7. no-column-names false
  8. no-csv-summary false
  9. no-progress false
  10. no-tab-scroll false
  11. with-mouse false
  12. agent-list false
  13. with-output-resolver false
  14. http-method yes
  15. http-protocol yes
  16. no-query-string false
  17. no-term-resolver false
  18. 444-as-404 false
  19. 4xx-to-unique-count false
  20. all-static-files false
  21. double-decode false
  22. ignore-crawlers false
  23. crawlers-only false
  24. ignore-panel REFERRERS
  25. ignore-panel KEYPHRASES
  26. real-os true
  27. static-file .css
  28. static-file .js
  29. static-file .jpg
  30. static-file .png
  31. static-file .gif
  32. static-file .ico
  33. static-file .jpeg
  34. static-file .pdf
  35. static-file .csv
  36. static-file .mpeg
  37. static-file .mpg
  38. static-file .swf
  39. static-file .woff
  40. static-file .woff2
  41. static-file .xls
  42. static-file .xlsx
  43. static-file .doc
  44. static-file .docx
  45. static-file .ppt
  46. static-file .pptx
  47. static-file .txt
  48. static-file .zip
  49. static-file .ogg
  50. static-file .mp3
  51. static-file .mp4
  52. static-file .exe
  53. static-file .iso
  54. static-file .gz
  55. static-file .rar
  56. static-file .svg
  57. static-file .bmp
  58. static-file .tar
  59. static-file .tgz
  60. static-file .tiff
  61. static-file .tif
  62. static-file .ttf
  63. static-file .flv

由上可见默认配置中并无时间参数,需要在配置中添加时间参数。

  1. [root@clsn.io /usr/local/etc/goaccess] clsn.io Blog WebSite
  2. #cat >>goaccess.conf<<EOF
  3. > time-format %H:%M:%S
  4. > date-format %d/%b/%Y
  5. > #NCSA Combined Log Format
  6. > log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
  7. > EOF
  8. [root@clsn.io /usr/local/etc/goaccess] clsn.io Blog WebSite
  9. #cp -a goaccess.conf ../

3.2 添加定时任务

  1. 30 * * * * /usr/local/bin/goaccess /var/log/nginx/clsn.io.log* -o /www/wwwroot/monitor/report.html -p /usr/
  2. local/etc/goaccess/goaccess.conf

3.3 检查生产页面

https://monitor.clsn.io/report.html
GoAccess日志分析工具 - 图4

4、参考文献

https://www.linuxidc.com/Linux/2016-12/138731.htm https://goaccess.io/man

https://goaccess.io/

https://www.imydl.tech/lnmp/197.html

https://segmentfault.com/a/1190000011025155