参考

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

ssh root@server 'zcat logs/access*.gz' | goaccess --log-format='%h [%d:%t %^] "%r" %s %b "%R" "%u" %T' --date-format=%d/%b/%Y --time-format=%T -o dist/report.html

展开

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"';

Goaccess解析nginx日志备忘的更多相关文章

  1. GoAccess分析Nginx日志详解

    一.为了提高 GoAccess 分析准确度,建议配置 nginx.conf 的 log_format 项如下: log_format main '$remote_addr - $remote_user ...

  2. Logstash使用grok插件解析Nginx日志

    grok表达式的打印复制格式的完整语法是下面这样的: %{PATTERN_NAME:capture_name:data_type}data_type 目前只支持两个值:int 和 float. 在线g ...

  3. ELK+Redis 解析Nginx日志

    一.ELK简介 Elk是指logstash,elasticsearch,kibana三件套,我们一般使用它们做日志分析. ELK工作原理图: 简单来讲ELK具体的工作流程就是客户端的logstash ...

  4. 在Centos中使用goaccess查看Nginx日志

    在Nginx的配置文件中配置一下access日志: log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘‘ ...

  5. Nginx日志监控 使用 goaccess查看nginx日志

    nginx日志监控 yum install goaccess   安装使用教程 goaccess access.log -o ../html/report.html --real-time-html ...

  6. [日志分析]Graylog2进阶 通过正则解析Nginx日志

    之前分享的 [日志分析]Graylog2采集Nginx日志 主动方式 这篇文章介绍了Graylog如何通过Graylog Collector Sidecar来采集nginx日志. 由于日志是未经处理的 ...

  7. GoAccess 分析 Nginx 日志

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

  8. 23、GoAccess分析Nginx日志

    1.GoAccess基本概述 GoAccess是一个基于终端的快速日志分析器.其核心思想是实时快速分析和查看Web服务器统计信息. 1.安装简单: 2.操作容易: 3.界面酷炫:  2.GoAcce ...

  9. 用GOACCESS分析NGINX日志

    参考URL: http://4b3r.com/goaccess-analyze-nginx-access-log/64/ http://jesuspan.sinaapp.com/crontab%E6% ...

随机推荐

  1. jQuery获取浏览器参数

    当我们需要获取浏览器参数是,我们可以使用jQuery进行获取,具体方法如下: 例如获取参数的地址:http://www.test.com?a="111"&b="2 ...

  2. Logstic回归采用sigmoid函数的原因

    ##Logstic回归采用sigmoid函数的原因(sigmoid函数能表示二项分布概率的原因) sigmoid函数: ![](http://images2017.cnblogs.com/blog/1 ...

  3. Python系列之 - 字符编码问题

    1.内存和硬盘都是用来存储的. CPU:速度快 硬盘:永久保存 2.文本编辑器存取文件的原理(nodepad++,pycharm,word) 打开编辑器就可以启动一个进程,是在内存中的,所以在编辑器编 ...

  4. 洛谷P2050 [NOI2012]美食节

    动态加边网络流 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring ...

  5. ●BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题解: LCT 如果把弹跳的起点和终点连一条边,弹出去的与n+1号点连边, 则不难发现 ...

  6. hdu 3473 划分树

    Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  7. 使用jquery.qrcode.js生成二维码

    通常生成二维码的方式有两种:第一种是java代码的形式,第二种是通过Js方式. 在这里我做个记录,用js生成二维码,可以在官网下载源码:http://jeromeetienne.github.io/j ...

  8. python中读取文件数据时要注意文件路径

    我们在用python进行数据处理时往往需要将文件中的数据取出来做一些处理,这时我们应该注意数据文件的路径.文件路径不对,回报如下错误: FileNotFoundError: File b'..Adve ...

  9. 在Unix系统中,主存索引节点和辅存索引节点从内容上比较有什么不同,为什么要设置主存索引节点?

    主存索引节点和辅存索引节点的不同主要体现在:主存索引节点状态:设备号.索引节点号:引用计数. 主存索引节点状态——反映主存索引节点的使用情况.它指示出: 1.  索引节点是否被锁上了: 2.  是否有 ...

  10. 阿里技术一面,Java研发岗

    之前过了个简单的简历面,过了几天后没打来以为凉了,然后昨晚又接到了电话,括号内容是回答说的,理解有限,不一定都对,欢迎纠正-加油每一个牛友们! 阿里一面: 1.学过哪些技术知识呢? 2.说说接口和抽象 ...