测试nginx状态信息的一个模块HttpLogRequestSpeed,找到网页瓶颈,官方提供了一个模块的源码和一个分析脚本,脚本是pl的。
、HttpLogRequestSpeed模块下载地址:
###HttpLogRequestSpeed Module###
http://wiki.nginx.org/File:Ngx_http_log_request_speed.tar.gz ###Log Analyzer.pl### http://wiki.nginx.org/File:Log_Analyzer.tar.gz
2、重新/全新编译
[root@ipython nginx]# ./sbin/nginx -V
nginx version: nginx/1.7.5 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) TLS SNI support enabled configure arguments: ...[省略] --add-module=../ngx_http_log_request_speed
3、Nginx配置:
###该过滤器支持使用在location, server, http####
http { ##enable / disable## log_request_speed_filter on; ##timeout## log_request_speed_filter_timeout 1; ##Log 级别需要注意一下,吐出来的log就在error里面## error_log /software/var_temp/log/nginx/nginx_error.log error; }
4、日志示例(输出域名做了修改):
[root@ipython nginx]# tail -5 /software/var_temp/log/nginx/nginx_error.log
2014/11/25 15:12:50 [error] 11374#0: *103177 --- process request time: 13961 ms --- while reading response header from upstream, client: 192.168.11.24, server: www.ipython.me, request: "GET /index.php HTTP/1.0", upstream: "fastcgi://unix:/dev/shm/php-cgi.sock:", host: "www.ipython.me" 2014/11/25 15:12:57 [error] 11374#0: *103216 --- process request time: 19090 ms --- while reading response header from upstream, client: 192.168.8.64, server: www.ipython.me, request: "GET /index.php?m=build&f=ajaxGetProjectBuilds&t=html&projectID=6&productID=9&varName=openedBuild&build=0&index=0&needCreate=true HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-cgi.sock:", host: "www.ipython.me", referrer: "http://www.ipython.me/index.php?m=bug&f=create&productID=9&extra=moduleID=0" 2014/11/25 15:15:01 [error] 11374#0: *133586 --- process request time: 28808 ms --- while reading response header from upstream, client: 192.168.8.64, server: www.ipython.me, request: "POST /index.php?m=bug&f=create&productID=9&extra=moduleID=0 HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-cgi.sock:", host: "www.ipython.me", referrer: "http://www.ipython.me/index.php?m=bug&f=create&productID=9&extra=moduleID=0" 2014/11/25 15:15:02 [error] 11374#0: *103216 --- process request time: 76462 ms --- while reading response header from upstream, client: 192.168.8.64, server: www.ipython.me, request: "GET /index.php?m=misc&f=ping&t=html HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-cgi.sock:", host: "www.ipython.me", referrer: "http://www.ipython.me/index.php?m=bug&f=create&productID=9&extra=moduleID=0" PROFILE: interrupts/evictions/bytes = 12095/260/113160
[root@ipython request_speed_log_analyzer]# cat /software/var_temp/log/nginx/nginx_error.log | grep "process request" | ./analyzer.pl -r
GET /index.php?m=story&f=ajaxGetProjectStories&t=html&projectID=6&productID=9&moduleID=0&storyID=0 HTTP/1.1 --- avg ms: 6554, value count: 1 GET /index.php?m=misc&f=qrCode HTTP/1.1 --- avg ms: 6632, value count: 1 GET /index.php?m=bug&f=ajaxLoadAssignedTo&t=html&projectID=6&selectedUser= HTTP/1.1 --- avg ms: 8451, value count: 1 GET /index.php?m=bug&f=ajaxGetModuleOwner&t=html&moduleID=0&productID=9 HTTP/1.1 --- avg ms: 8590, value count: 1 GET /index.php?m=bug&f=create&productID=9&extra=moduleID=0 HTTP/1.1 --- avg ms: 9204, value count: 1 GET /index.php?m=task&f=ajaxGetProjectTasks&t=html&projectID=6&taskID=0 HTTP/1.1 --- avg ms: 9726, value count: 1 GET /index.php HTTP/1.0 --- avg ms: 11073, value count: 226 GET /index.php?m=build&f=ajaxGetProjectBuilds&t=html&projectID=6&productID=9&varName=openedBuild&build=0&index=0&needCreate=true HTTP/1.1 --- avg ms: 19090, value count: 1 POST /index.php?m=bug&f=create&productID=9&extra=moduleID=0 HTTP/1.1 --- avg ms: 28808, value count: 1 GET /index.php?m=misc&f=ping&t=html HTTP/1.1 --- avg ms: 76462, value count: 1 <--- THE WINNER ##Help## [root@test-centos-24 request_speed_log_analyzer]# ./analyzer.pl -h -h : this help message -u : group by upstream -o : group by host -r : group by request (责任编辑:IT) |