2019独角兽企业重金招聘Python工程师标准>>>

一.简介
1.goaccess用于分析apache和nginx日志的强大工具

2.官网:
https://goaccess.io

二.安装
1.下载goaccess的安装包
wget http://tar.goaccess.io/goaccess-1.1.1.tar.gz

2.如果需要启用geoip,则1.1的版本,需要geoip.1.4.7的版本,编译安装geoip.1.4.7

cd /usr/local/src
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.7.tar.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

tar xzvf GeoIP-1.4.7.tar.gz
cd GeoIP-1.4.7
./configure && make && make install
mv GeoIP.dat.gz /usr/local/share/GeoIP/

3.编译安装goaccess

tar -xzvf goaccess-0.8.1.tar.gz
cd goaccess-0.8.1/
tar -xzvf goaccess-1.1.1.tar.gz 
cd goaccess-1.1.1/
./configure --enable-geoip --enable-utf8 
make
make install

如果出现
goaccess: error while loading shared libraries: libGeoIP.so.1
错误

ln -s /usr/local/lib/libGeoIP.so* /lib64/

三.使用
1.简单使用
goaccess -f access.log

2.使用指定的配置文件
wget -O .goaccessrc https://raw.githubusercontent.com/allinurl/goaccess/master/config/goaccess.conf --no-check-certificate

vi .goaccessrc
选择和编辑合适的date-format,log-format,time-format

goaccess -f access.log -d -a -p ~/.goaccessrc

输出到文件便于web查看

goaccess -f access.log -d -a -p ~/.goaccessrc > log.html

更多详细的使用:https://goaccess.io/man

Goaccess解析nginx日志备忘

参考

http://nginx.org/en/docs/http/ngx_http_log_module.html?&_ga=1.92028562.949762386.1481787781#log_format
https://www.goaccess.io/man#custom-log

展开

goaccess默认的日志格式与nginx的默认格式一致

%h %^[%d:%t %^] "%r" %s %b "%R" "%u"log_format combined '$remote_addr - $remote_user [$time_local] ''"$request" $status $body_bytes_sent ''"$http_referer" "$http_user_agent"';

自定义日志格式

现在增加一个响应时间, 删除$remote_user, 并把$body_bytes_sent修改为$bytes_sent,

修改nginx.conf

log_format myfmt '$remote_addr [$time_local] ''"$request" $status $bytes_sent ''"$http_referer" "$http_user_agent" $request_time';
access_log logs/access.log myfmt;

修改goaccess 配置文件

# vim /usr/local/etc/goaccess.conf
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h [%d:%t %^] "%r" %s %b "%R" "%u" %T

执行示例

cat logs/access.log | goaccess -o ~/static/report.html

goaccess -f logs/access.log -o ~/static/report.html --real-time-html

变量说明

1.$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;2.$remote_user :用来记录客户端用户名称;3.$time_local : 用来记录访问时间与时区;4.$request : 用来记录请求的url与http协议;5.$status : 用来记录请求状态;成功是200,6.$body_bytes_sent :记录发送给客户端文件主体内容大小;7.$http_referer :用来记录从那个页面链接访问过来的;8.$http_user_agent :记录客户端浏览器的相关信息;

nginx日志相关

Syntax: log_format name [escape=default|json] string ...;
Default:
log_format combined "...";
Context: http
Specifies log format.

The escape parameter (1.11.8) allows setting json or default characters escaping in variables, by default, default escaping is used.

The log format can contain common variables, and variables that exist only at the time of a log write:

$bytes_sent
the number of bytes sent to a client
$connection
connection serial number
$connection_requests
the current number of requests made through a connection (1.1.18)
$msec
time in seconds with a milliseconds resolution at the time of the log write
$pipe
“p” if request was pipelined, “.” otherwise
$request_length
request length (including request line, header, and request body)
$request_time
request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client
$status
response status
$time_iso8601
local time in the ISO 8601 standard format
$time_local
local time in the Common Log Format
In the modern nginx versions variables $status (1.3.2, 1.2.2), $bytes_sent (1.3.8, 1.2.5), $connection (1.3.8, 1.2.5), $connection_requests (1.3.8, 1.2.5), $msec (1.3.9, 1.2.6), $request_time (1.3.9, 1.2.6), $pipe (1.3.12, 1.2.7), $request_length (1.3.12, 1.2.7), $time_iso8601 (1.3.12, 1.2.7), and $time_local (1.3.12, 1.2.7) are also available as common variables.
Header lines sent to a client have the prefix “sent_http_”, for example, $sent_http_content_range.

The configuration always includes the predefined “combined” format:

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

转载于:https://my.oschina.net/mickelfeng/blog/1922660

goaccess的安装和使用相关推荐

  1. goaccess的安装、使用及介绍【实操完整版】

    goaccess的安装.使用及介绍 goaccess的安装.使用及介绍 一.安装goaccess 二.启动 1.第一种,用定时任务,定时生成html 2.第二种,改配置文件,让goaccess在后台运 ...

  2. Goaccess安装与使用

    最近项目中需要对nginx日志文件进行分析,于是使用goaccess工具进行操作. goaccess官网:https://goaccess.io/ goaccess的安装(linux服务器操作) 1. ...

  3. Linux安装GoAccess

    GoAccess下载地址:https://goaccess.io/download 1.下载.安装GoAccess $ wget https://tar.goaccess.io/goaccess-1. ...

  4. GoAccess 安装

    GoAccess 安装 安装 二进制安装 以 Ubuntu 为例 echo "deb http://deb.goaccess.io/ $(lsb_release -cs) main" ...

  5. 在Linux中使用GoAccess分析Nginx的日志

    一 GoAccess简介 GoAccess是一款日志分析工具,可以用来分析Apache,IIS,Nginx的日志,或者一些其他web服务的日志.其特点是安装简单,使用方便,分析速度快 二 GoAcce ...

  6. GoAccess日志分析工具,适用于Nginx/Apache/IIS 等

    最近了解到一款Nginx日志分析工具GoAccess ,这里记录一下. 1 介绍 GoAccess 是一款开源(MIT许可证)的且具有交互视图界面的实时 Web 日志分析工具,通过你的 Web 浏览器 ...

  7. GoAccess轻量nginx日志分析工具

    什么是GoAccess GoAccess 是一款开源.实时,运行在命令行终端下的 Web 日志分析工具. 该工具提供快速.多样的 HTTP 状态统计. 分析结果,可以通过 XShell 等客户端工具查 ...

  8. Lamp——nginx日志分析工具goaccess

    nginx日志分析工具goaccess 编译安装goaccess 使用goaccess nginx日志内容太多.有必要使用分析工具goaccess,有助于高效查看分析日志内容. 编译安装goacces ...

  9. 小而美的Nginx日志分析利器GoAccess

    一般会把Nginx的日志导入日志系统进行实时或者准实时的分析,不过不是每个公司都有这样的环境,还有有时候临时就是想分析监控下Nginx,那么GoAccess就很适合你,这块工具小而美,功能很强大. G ...

最新文章

  1. 装饰模式(Decorator Pattern)
  2. RestHighLevelClient 批量插入 elasticsearch 7.9 版本警告
  3. 未明确定义列存储过程没问题_使用Apache Kudu和Impala实现存储分层
  4. MFC ListCtrl和IP控件的使用杂记
  5. sql字符串拼接_Mybatis的SqlSession执行sql过程
  6. 云+X案例展 | 传播类:南方报业数据中台建设,助力“智媒”飞跃发展
  7. mastercam加工报表生成_听说最厉害的工程师才敢这样玩五轴加工?
  8. Windows 文件含义大全
  9. PPT模板(淘宝花钱买来的,免费分享给大家)
  10. java web 调度_javaweb车辆调度信息管理平台
  11. java留言板_java实现简单留言板功能的代码实例
  12. 高效记忆/形象记忆(07)110数字编码表 11-20
  13. Eclipse安装SVN插件最新版本 Subclipse
  14. leaflet 加载海量点位,点击marker 查看详情功能
  15. 使用EXCEL计算并绘制RSI指标
  16. 学习vue之前应该有哪些基础知识
  17. 可以当零食吃的排骨——椒盐排骨
  18. IPV6邻居发现协议(NDP)
  19. 机器学习中常用的分类算法总结
  20. 17.7.19-聊天APP-登录界面

热门文章

  1. 拜耳扫地机器人_realme真我旅行箱发布 37L超大容量拜耳材质售299元
  2. 防火墙双机热备配置实例(一)
  3. mysql 子查询执行顺序_关联子查询的执行顺序是什么
  4. 全球及中国核电行业建设动态及项目运营状况分析报告2021-2027年
  5. MySQL中tinytext、text、mediumtext和longtext等各个类型详解
  6. mysql 迁移数据库到另一台服务器
  7. 详述Servlet获取form表单数据
  8. 读取grib文件,批量转为nc
  9. 雷达系统设计及matlab仿真(一) 第一章 雷达基础知识概论(测距 距离分辨率 多普勒频率 雷达方程 噪声和信噪比 脉冲积累)
  10. 拍森 | numpy库