1. GoAccess常见问题

GoAccess实战秘籍:从新手到高手,跨越那些“坑”与“惑”!

微信公众号: 雪之梦技术驿站


致读者: 点击上方 “雪之梦技术驿站” → 点击右上角“ ... ”→ 点选“设为星标★ ” 加上星标,就不会找不到我啦!

偷偷溜进文章的小广告,别害羞,点进去瞅瞅,说不定能发现什么宝藏呢!文末那个也别错过,说不定是通往秘密花园的钥匙哦!

🌟 大家好,欢迎来到「雪之梦技术驿站」🚀 今天,我们就来一场说走就走的GoAccess探险之旅,不仅揭秘那些让你头疼不已的问题,还亲手为你铺设一条从新手到高手的快速通道。

GoAccess 是一款开源的且具有交互视图界面的实时 Web 日志分析工具,通过你的 Web 浏览器或者 *nix 系统下的终端程序(terminal)即可访问。能为系统管理员提供快速且有价值的 HTTP 统计,并以在线可视化服务器的方式呈现。摘录自中文翻译网站: https://www.goaccess.cc/

无论你是刚开始接触日志分析的新手,还是想要提升效率的老鸟,这篇文章都将是你不可多得的宝藏地图!

🔍 首先,让我们直击痛点,聊聊那些在使用GoAccess过程中,你最可能遇到的几个‘坑’:

  • 配置迷茫:面对复杂的配置文件,是不是常常感到无从下手,不知道哪些设置才是最适合自己的需求?
  • 性能瓶颈:随着数据量的激增,GoAccess是否还能保持其轻盈的身姿,流畅地展示分析结果?
  • 数据导入难题:如何将Nginx、Apache等服务器的日志文件无缝导入GoAccess,实现一键分析?
  • 报表定制:如何根据自己的需求,定制出既美观又实用的报表,让数据说话更有力?

🎉 准备好了吗?让我们一起踏上这场充满挑战与收获的旅程,让GoAccess成为你日志分析领域的得力助手!

# 生成一份 HTML 报告  
goaccess access.log -a -o report.html

详细配置选项请参考官方用户手册

1.1. 常用配置

1.1.1. 语言时区等设置

默认英文环境,需求为更改为中文环境 zh_CN.UTF-8

如果系统是英文环境则GoAccess日志监测报告也是英文,查看默认echo $LANG环境变量!

所以想要GoAccess显示中文,只需要将环境变量设置为中文即可 LANG="zh_CN.UTF-8"

1.1.2. 请求的文件

请求链接携带参数,需求为忽略请求参数,精简get请求url

如果是get请求会携带大量的参数,也会展示多条记录,显得非常凌乱,因此需要忽略query参数部分

-q --no-query-string  
Ignore request's query string. i.e., www.google.com/page.htm?query => www.google.com/page.htm  
Note: Removing the query string can greatly decrease memory consumption, especially on timestamped requests.

1.1.3. 访客主机名和IP地址

只能看到具体的ip数据,无法直观查看ip归属地,需求是解析ip地理位置

开启地理位置解析,指定离线ip数据库文件,具体操作可参考: 你的网站访客来自何方?GoAccess地理分析工具告诉你!

--geoip-database <geocityfile>  
Specify path to GeoIP database file. i.e., GeoLiteCity.dat. File needs to be downloaded from maxmind.com. IPv4 and IPv6 files are supported as well. Note: --geoip-city-data is an alias of --geoip-database.  
Note: If using GeoIP2, you will need to download the City/Country database from MaxMind and use the option --geoip-database to specify the database. Currently cities are only shown in the hosts panel (per host).

1.1.4. 操作系统

未知数据Unknown单独占比是不太科学的,需求是归类为爬虫Crawlers记录

--unknowns-as-crawlers  
Classify unknown OS and browsers as crawlers. As an attempt to detect non-humans more accurately, an option to classify unknown OS and browsers and crawlers help.

1.1.5. 时间分配

默认按照小时统计,特殊情况下也可以指定按照分钟统计

--hour-spec=<hour|min>  
Set the time specificity to either hour (default) or min to display the tenth of an hour appended to the hour.  
This is used in the time distribution panel. It's useful for tracking peaks of traffic on your server at specific times.

1.1.6. 地理位置

需要开启地理位置选项,来源于解析ip对应的地理位置统计展示的数据,否则没有该面板.

--geoip-database <geocityfile>  
Specify path to GeoIP database file. i.e., GeoLiteCity.dat. File needs to be downloaded from maxmind.com. IPv4 and IPv6 files are supported as well. Note: --geoip-city-data is an alias of --geoip-database.  
Note: If using GeoIP2, you will need to download the City/Country database from MaxMind and use the option --geoip-database to specify the database. Currently cities are only shown in the hosts panel (per host).

具体操作可参考: 你的网站访客来自何方?GoAccess地理分析工具告诉你!

1.2. 总结

本文主要介绍了GoAccess使用过程中的关于面板的常用配置选项,反复查看配置文档的吐血总结,争取新人不用再看繁琐的用户手册就能直接上手.如果是您正在使用的是默认的nginx日志格式,那么接下来的命令可以参考使用.请先确认nginx日志格式 --log-format=COMBINED

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

    access_log  /var/log/nginx/access.log  main;  
    ...      
}

如果是其他web日志格式,请参考https://goaccess.io/man

--log-format <logformat>  
The log-format variable followed by a space or \t for tab-delimited, specifies the log format string.  

In addition to specifying the raw log/date/time formats, for simplicity, any of the following predefined log format names can be supplied to the log/date/time-format variables. GoAccess can also handle one predefined name in one variable and another predefined name in another variable.  

COMBINED     | 联合日志格式  
VCOMBINED    | 支持虚拟主机的联合日志格式  
COMMON       | 通用日志格式  
VCOMMON      | 支持虚拟主机的通用日志格式  
W3C          | W3C 扩展日志格式  
SQUID        | Native Squid 日志格式  
CLOUDFRONT   | 亚马逊 CloudFront Web 分布式系统  
CLOUDSTORAGE | 谷歌云存储  
AWSELB       | 亚马逊弹性负载均衡  
AWSS3        | 亚马逊简单存储服务 (S3)

最后,静态报告基本命令如下:

# 静态报告  
goaccess /var/log/nginx/access.log --log-format=COMBINED \  
 # ip地理解析数据库文件  
 --geoip-database=/GeoLite2-City.mmdb \  
 # ip地理解析数据库文件  
 --geoip-database=/GeoLite2-City.mmdb \  
 # 忽略GET请求查询参数  
 -q \  
 # 未知用户代理设为爬虫  
 --unknowns-as-crawlers  
 # 输出到web静态路径  
 -o /var/www/html/report.html

实时报告如下,需要配置websocket等选项,关注上一篇历史文章有专门的详细介绍!

goaccess /var/log/nginx/access.log --log-format=COMBINED \  
 # 实时日志相关配置  
 --real-time-html \  
 --ws-url=wss://js56.cn:443/goaccess/webSocket \  
 --origin=https://js56.cn \  
 --port=7890 \  
 --ping-interval=60 \  
 # ip地理解析数据库文件  
 --geoip-database=/GeoLite2-City.mmdb \  
 # 忽略GET请求查询参数  
 -q \  
 # 未知用户代理设为爬虫  
 --unknowns-as-crawlers  
 # 输出到web静态路径  
 -o /var/www/html/report.html

嘿,小伙伴们,你们知道吗?这字儿可不是白码的,每一颗键帽下的汗水都能浇出一朵花来!所以,要是看得开心,就请大方地撒点阳光——评论点赞转发走一波,让我这花园更加灿烂!

1.3. 往期精彩文章

1.4. 欢迎扫码关注

微信公众号「雪之梦技术驿站」

欢迎扫码关注,私信回复『加群』一起交流技术

最后更新时间: 2024-09-12 15:31:28
作者: 雪之梦技术驿站
来源: 雪之梦技术驿站
本文原创发布于「雪之梦技术驿站」,转载请注明出处,谢谢合作!

/snowdreams1006-wechat-open.png

results matching ""

    No results matching ""