1、GoAccess简介
GoAccess是一个非常良心的开源软件,它的良心之处体现在如下方面:
- 安装简单;
- 操作容易;
- 界面酷炫;
GoAccess 官网 https://goaccess.io
2、安装GoAccess
2.1 系统环境说明
[root@clsn.io /root]#cat /etc/redhat-releaseCentOS release 6.8 (Final)[root@clsn.io /root]#uname -aLinux 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[root@clsn.io /root]#sestatusSELinux status: disabled
2.2 安装GoAccess
官网提供多种系统版本的安装方法: https://goaccess.io/download#installation
$ wget https://tar.goaccess.io/goaccess-1.3.tar.gz$ tar -xzvf goaccess-1.3.tar.gz$ cd goaccess-1.3/$ ./configure --enable-utf8 --enable-geoip=legacy$ make# make install
配置完成的信息
Your build configuration:Prefix : /usr/localPackage : goaccessVersion : 1.3Compiler flags : -pthreadLinker flags : -lnsl -lncursesw -lGeoIP -lpthreadDynamic buffer : noGeolocation : GeoIP LegacyStorage method : In-memory Hash Database (Default)TLS/SSL : noBugs : goaccess@prosoftcorp.com
2.3 使用GoAccess分析日志
注:本次分析日志为 nignx 标准输出日志
[root@clsn.io /var/log/nginx] clsn.io Blog WebSite#goaccess -f clsn.io.log
日志格式选为 NCSA Combined Log Format
回车即可看到当前日志分析结果
3、生成HTML页面
3.1 修改配置
查看当前配置
[root@clsn.io /usr/local/etc/goaccess] clsn.io Blog WebSite#egrep -v "^#|^$" goaccess.confconfig-dialog falsehl-header truejson-pretty-print falseno-color falseno-column-names falseno-csv-summary falseno-progress falseno-tab-scroll falsewith-mouse falseagent-list falsewith-output-resolver falsehttp-method yeshttp-protocol yesno-query-string falseno-term-resolver false444-as-404 false4xx-to-unique-count falseall-static-files falsedouble-decode falseignore-crawlers falsecrawlers-only falseignore-panel REFERRERSignore-panel KEYPHRASESreal-os truestatic-file .cssstatic-file .jsstatic-file .jpgstatic-file .pngstatic-file .gifstatic-file .icostatic-file .jpegstatic-file .pdfstatic-file .csvstatic-file .mpegstatic-file .mpgstatic-file .swfstatic-file .woffstatic-file .woff2static-file .xlsstatic-file .xlsxstatic-file .docstatic-file .docxstatic-file .pptstatic-file .pptxstatic-file .txtstatic-file .zipstatic-file .oggstatic-file .mp3static-file .mp4static-file .exestatic-file .isostatic-file .gzstatic-file .rarstatic-file .svgstatic-file .bmpstatic-file .tarstatic-file .tgzstatic-file .tiffstatic-file .tifstatic-file .ttfstatic-file .flv
由上可见默认配置中并无时间参数,需要在配置中添加时间参数。
[root@clsn.io /usr/local/etc/goaccess] clsn.io Blog WebSite#cat >>goaccess.conf<<EOF> time-format %H:%M:%S> date-format %d/%b/%Y> #NCSA Combined Log Format> log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"> EOF[root@clsn.io /usr/local/etc/goaccess] clsn.io Blog WebSite#cp -a goaccess.conf ../
3.2 添加定时任务
30 * * * * /usr/local/bin/goaccess /var/log/nginx/clsn.io.log* -o /www/wwwroot/monitor/report.html -p /usr/local/etc/goaccess/goaccess.conf
3.3 检查生产页面
https://monitor.clsn.io/report.html
4、参考文献
https://www.linuxidc.com/Linux/2016-12/138731.htm https://goaccess.io/man
