[转帖]查看请求在nginx中消耗的时间

查看,请求,nginx,消耗,时间 · 浏览次数 : 0

小编点评

```nginx # Add log_format directive log_format test '$remote_addr - $remote_user [$time_local] \"$request\" ' '$status $body_bytes_sent $request_body \"$http_referer\" ' '\"$http_user_agent\" \"$http_x_forwarded_for\"' '$upstream_addr $upstream_response_time $request_time '; # Add access_log directive access_log logs/test.log test; # Analyze and extract the data cat test.log | grep url | awk '{print $6 " " $7 " " $8 " " $11 " " ($NF-$(NF-1))}' > c.txt ``` **Explanation:** 1. **log_format directive**: This directive defines a custom log format named "test". The format uses a series of placeholders to represent various variables, including remote address, user, request time, status code, request body, referer, user agent, forwarded for, upstream address, response time, and request time. 2. **access_log directive**: This directive specifies an access log called "test" for the "test" log format. 3. **cat command**: This command reads the "test.log" file and filters the output to extract lines containing the word "url". 4. **awk script**: The "awk" script processes the extracted lines and prints the following information for each match: - Remote address - Remote user - Request time - Status code - Request body size - Referer - User agent - Forwarded for address - Upstream address and response time - Request time 5. **> c.txt**: This command redirects the output of the "awk" script to a file named "c.txt". 6. **Output summary**: The script will generate a file named "c.txt" containing a summary of the requests that took the longest time to process. Each line in this file will represent the URL, request time, and the corresponding user agent and response time.

正文

需求:查看请求在nginx中消耗的时间,不包括程序响应时间。

1.声明日志的格式,在nginx配置文件nginx.conf里的http下添加如下内容:

  1. log_format test '$remote_addr - $remote_user [$time_local] "$request" '
  2. '$status $body_bytes_sent $request_body "$http_referer" '
  3. '"$http_user_agent" "$http_x_forwarded_for"'
  4. '$upstream_addr $upstream_response_time $request_time ';

2.在需要日志的server下添加:

access_log logs/test.log test;

3.分析nginx的日志,查出需要查看消耗时间的url,用$request_time减掉$upstream_response_time。

cat test.log | grep url | awk '{print $6 " " $7 " " $8 " " $11 " " ($NF-$(NF-1))}' > c.txt

与[转帖]查看请求在nginx中消耗的时间相似的内容:

[转帖]查看请求在nginx中消耗的时间

需求:查看请求在nginx中消耗的时间,不包括程序响应时间。 1.声明日志的格式,在nginx配置文件nginx.conf里的http下添加如下内容: log_format test '$remote_addr - $remote_user [$time_local] "$request" ' '$

[转帖] Jmeter学习笔记(七)——监听器元件之察看结果树

https://www.cnblogs.com/pachongshangdexuebi/p/11507289.html 在jmeter中,如果我们需要查看请求结果就需要添加查看结果树,这个监听器元件有那些功能呢? 一、察看结果树界面如下 二、察看结果树界面功能说明 1、所有数据写入文件 (1)文件名

[转帖]jmeter正则表达式应用-01篇

如图所示 1.先新建一个login的http请求,然后再login的请求下新增一个正则表达式提取器,增加一个查看结果树查看结果 假如后端接口返回的数据为"{'msg': 'login success', 'code': 1001, 'token': '48b2837a33461f58988ae72b

[转帖]jmeter 响应时间rt很小,但是tps也很小&jmeter,脚本处理,千万不要用js

一、背景: 在压测的时候,查看jmeter聚合报告,发现rt很小,但是tps也很小。 讲道理来说,响应时间越小,tps应该越大。 一共压测10分钟,发现jmeter请求的样本数量非常小,才8500个请求。 10分钟内,才打出了8500个请求。 tps= 总样本数量/总时间。 时间是固定的600s,总

[转帖]Centos 7 查看磁盘io ,找出占用io读写很高的进程

1,先用iostat查看磁盘io 是否读写负载很高 用iostat -x 1 10 如果 iostat 没有,要 yum install sysstat安装这个包,第一眼看下图红色圈圈的那个如果%util接近100%,表明I/O请求太多,I/O系统已经满负荷,磁盘可能存在瓶颈,一般%util大于70

[转帖]tcpdump非常实用的抓包实例

https://www.jianshu.com/p/83cf0e64a654 参考资料:http://www.jianshu.com/p/3cca9a74927c <<亲测可用tcpdump查看HTTP流量查看>> 抓包HTTP GET请求: [root@hostname /]# sudo tcpd

[转帖]Nginx报错404,由于请求处理时间过长

问题复现 近期部门内部有一个应用由于数据量过于庞大,或者说sql优化性能问题,导致查询全量数据时老报错nginx404,后来查看浏览器timing信息,发现其竟然时常达到可怕的2分钟十秒,抛去解决sql优化问题,这里从Nginx端的配置来说如何解决这类问题! 存在的问题 服务器处理请求时间过长,导致

[转帖]Redis故障检查:识别慢查询操作

https://weibo.com/ttarticle/p/show?id=2309404650615585505652 使用SLOWLOG命令查看Redis中的慢查询操作。 ​​前几篇日志总结了下对Redis部署时的一些配置,Redis启动后,面对各种请求,数据持久化到硬盘,很可能会出现内存不足等

[转帖]Linux 系统TCP连接内存大小限制 调优

https://www.cnblogs.com/liujunjun/p/12496677.html 系统TCP连接内存大小限制 TCP的每一个连接请求,读写都需要占用系统内存资源,可根据系统配置,对TCP连接数,内存大小,限制调优。 查看系统内存资源 记录内存 详情:cat /proc/meminf

[转帖]Jmeter插件之ServerAgent服务器性能监控工具的安装和使用

https://www.cnblogs.com/pachongshangdexuebi/p/13354201.html 一、前言 性能测试时我们关注的重要指标是:并发用户数,TPS,请求成功率,响应时间,服务器的CPU,memory, I/O disk等。Jmeter的聚合报告可以查看并发数、吞吐量