Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1426|回复: 2
打印 上一主题 下一主题

Nginx日志分析

[复制链接]

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
跳转到指定楼层
楼主
发表于 2018-4-24 11:51:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 java 于 2018-4-24 12:36 编辑
  1. '$remote_addr - $remote_user [$time_local] "$request" $http_host '
  2. '$status $request_length $body_bytes_sent "$http_referer" '
  3. '"$http_user_agent"  $request_time';

  4. 字段解释:

  5. remote_addr : 客户端地址
  6. remote_user : 客户端用户名
  7. time_local : 服务器时间
  8. request : 请求内容,包括方法名,地址,和http协议
  9. http_host : 用户请求时使用的http地址
  10. status : 返回的http 状态码
  11. request_length : 请求大小
  12. body_bytes_sent : 返回的大小
  13. http_referer : 来源页
  14. http_user_agent : 客户端名称
  15. request_time : 整体请求延时

  16. 日志格式:'$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'



  17. 日志记录:27.189.231.39 - - [09/Apr/2016:17:21:23 +0800] "GET /Public/index/images/icon_pre.png HTTP/1.1" 200 44668 "http://www.test.com/Public/index/css/global.css" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" "-"

  18. 配置log_format
  19. nginx.conf
  20.   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

  21.                               '$status $body_bytes_sent $request_body "$http_referer" '

  22.                               '"$http_user_agent" "$http_x_forwarded_for" "$request_time"';


  23. 主要使用的是grep,awk,cut等工具来对nginx日志进行统计和分析

  24. Awk中数组称为关联数组,因为它的下标(索引)可以是数字也可以是字符串。

  25. 下标通常称为键,数组元素的键和值存储在Awk程序内部的一个表中,该表采用散列算法,因此数组元素是随机排序。

  26. cat:输入文件内容

  27. grep:过滤文本

  28. 'sort':排序

  29. 'uniq':去重

  30. 'awk':文本处理

  31. 命令组合使用,单个命令可以使用多次,来达到多重过滤的效果,前面一个命令的输出就是后一个命令的输入,流式处理,只要学会这个命令,有多看似复杂的东西,都变得异常简单。
复制代码
问题:nginx如何计算请求在队列中的等待时间

https://stackoverflow.com/questions/46319833/log-nginx-queue-time   好像不支持


  1.     $request_time

  2.         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

  3.     $upstream_response_time

  4.         keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution.

  5.     $upstream_header_time

  6.         keeps time spent on receiving the response header from the upstream server (1.7.10); the time is kept in seconds with millisecond resolution.

  7. but all of them report the same time, about 5 second, for both requests.
复制代码
回复

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
沙发
 楼主| 发表于 2018-4-24 14:24:50 | 只看该作者
1. $request_time
官方文档对 $request_time 的解释(链接:Module ngx_http_core_module):


2. $upstream_response_time
官方文档对 $upstream_response_time 的解释(链接:Module ngx_http_upstream_module):
回复 支持 反对

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
板凳
 楼主| 发表于 2018-4-24 15:03:12 | 只看该作者
1xx(临时响应)
2xx (成功)
3xx (重定向)
4xx(请求错误)
5xx(服务器错误)

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-6 22:48 , Processed in 0.057702 second(s), 18 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表