参考

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. monogodb3.4安装修改,权限设置

    下载地址:https://www.mongodb.com/download-center#community 这里的方法只对应3.4,别的有没有效果请自行判断. 下载后按默认下一步. 默认安装地址  ...

  2. Array方面Js底层代码学习记录

    一..clear() →Array function clear() { this.length = 0; return this; } 返回清除item的空数组. 例子: var fruits = ...

  3. 1025InnoDB log file 设置多大合适

    转自 http://blog.csdn.net/langkeziju/article/details/51094289 数据库的东西,往往一个参数就牵涉N多知识点.所以简单的说一下.大家都知道inno ...

  4. django 开发忘记密码通过邮箱找回功能

    一.流程分析: 1.点击忘记密码====>forget.html页面,输入邮箱和验证码,发送验证链接网址的邮件====>发送成功,跳到send_success.html提示 2.到邮箱里找 ...

  5. reportng优化

    本来呢,我是看到报告中没有输出@Test的description 的属性,想优化一下,没想到在找reportng的源码的时候,发现一个大神也优化了reportNG,他优化了下面几个内容: 1).测试结 ...

  6. 自定义Loader

    自定义Loader涉及到的接口: public delegate byte[] CustomLoader(ref string filePath); public void LuaEnv.AddLoa ...

  7. [LeetCode] Pour Water 倒水

    We are given an elevation map, heights[i] representing the height of the terrain at that index. The ...

  8. 深入解析 SQL Server 高可用镜像实现原理

    作者:郭忆 本文由 网易云 发布. SQL Server 是 windows 平台 .NET 架构下标配数据库解决方案,与 Oracle.MySQL 共同构成了 DB-Engines Ranking ...

  9. 简明shell入门

  10. StandardContext

    错误信息: 2014-2-6 21:37:19 org.apache.catalina.startup.HostConfig checkResources信息: Reloading context [ ...