200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > nginx post请求超时_nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)

nginx post请求超时_nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)

时间:2023-07-15 05:47:36

相关推荐

nginx post请求超时_nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)

nginx模块ngx_http_log_request_speed可以用来找出网站哪些请求很慢,针对站点很多,文件以及请求很多想找出哪些请求比较慢的话,这个插件非常有效.作者的初衷是写给自己用的,用来找出站点中处理时间较长的请求, 这些请求是造成服务器高负载的很大根源. 日志记录之后,在使用perl脚本分析日志,即可知道哪些请求需要修正.

1. 模块安装

nginx第三方模块安装方法,我们已经说过很多次了,我这边不在重复了。

配置参数

./configure --prefix=/usr/local/nginx-1.4.1 --with-http_stub_status_module \

--add-module=../ngx_http_log_request_speed

1

2

./configure--prefix=/usr/local/nginx-1.4.1--with-http_stub_status_module\

--add-module=../ngx_http_log_request_speed

2. 指令log_request_speed

log_request_speed_filter

语法: log_request_speed_filter [on|off]

配置段: n/a

context: location, server, http

启动或禁用模块

log_request_speed_filter_timeout

语法: log_request_speed_filter_timeout [num sec]

默认: 5秒

配置段: location, server, http

这边并不是真正意义的超时,而是说当请求超过这边给定的时间,将会记录到nginx错误日志中. 默认值是5000微秒(5秒),如果一个请求小于5秒,这个请求不会被记录到日志中,但是如果超过5秒,那请求将会被记录到nginx的错误日志中

3. 使用实例

3.1 nginx配置

http{

log_request_speed_filter on;

log_request_speed_filter_timeout 3;

...

}

1

2

3

4

5

http{

log_request_speed_filteron;

log_request_speed_filter_timeout3;

...

}

错误日志中记录的慢请求如下

nginx慢请求日志

3.2 日志分析

cd /usr/local/nginx-1.4.1/logs

wget /images/a/a8/Log_Analyzer.tar.gz

tar -xzvf Log_Analyzer.tar.gz

cd request_speed_log_analyzer

# cat ../error.log | grep 'process request'| ./analyzer.pl -r

POST /wp-admin/admin-ajax.php HTTP/1.1 --- avg ms: 1182, value count: 2

GET /shmb/1145.html HTTP/1.1 --- avg ms: 2976, value count: 1

1

2

3

4

5

6

7

cd/usr/local/nginx-1.4.1/logs

wget/images/a/a8/Log_Analyzer.tar.gz

tar-xzvfLog_Analyzer.tar.gz

cdrequest_speed_log_analyzer

# cat ../error.log | grep 'process request'| ./analyzer.pl -r

POST/wp-admin/admin-ajax.phpHTTP/1.1---avgms:1182,valuecount:2

GET/shmb/1145.htmlHTTP/1.1---avgms:2976,valuecount:1

从日志中,我们发现这边有2条请求比较慢,最慢的是/shmb/1145.html ,而且还标示“THE WINNER”,作者你赢了。很幽默。

3.3 分析脚本语法

# ./analyzer.pl -h

-h : this help message # 显示帮助信息

-u : group by upstream # 按upstream分组

-o : group by host # 按主机分组

-r : group by request # 按请求分组,推荐这个

1

2

3

4

5

# ./analyzer.pl -h

-h:thishelpmessage# 显示帮助信息

-u:groupbyupstream# 按upstream分组

-o:groupbyhost# 按主机分组

-r:groupbyrequest# 按请求分组,推荐这个

4. nginx测试版本

目前作者只在0.6.35和0.7.64下测试,不保证其他环境下可以使用。我当前的测试版本是1.4.1,目前使用正常,在使用前请大家先测试一下。

5. 结束语

首先很感谢作者写的这个简单实用的nginx插件,这个插件的目的不仅仅是记录请求的响应时间,而且是用来找出响应慢的请求。如果你的服务器上有大量的站点,或者大量的程序文件,但是访问量不高,负载却很高,你想找出是哪个请求慢,我想这个插件非常适合你。

参考地址

ngx_http_log_request_speed下载地址:/images/7/78/Ngx_http_log_request_speed.tar.gz

ngx_http_log_request_speed脚本地址:/images/a/a8/Log_Analyzer.tar.gz

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。