awk分析nginx日志里面的接口响应时间

最近,有客户反应客户端卡,老板集合技术人员开会讨论,找出慢的原因,由此产生了分析nginx响应时间,由于线上环境nginx日志格式带上了引号,处理起来有点麻烦,以下是处理过程

一、nginx日志格式

log_format main ‘$remote_addr – $remote_user [$time_iso8601] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for” ‘
‘ “$upstream_addr” “$upstream_status” “$request_time” ‘;

二、nginx访问日志(/var/log/nginx)

12.124.127.44 – – [29/Jul/2014:20:54:20 +0800] “GET / HTTP/1.1″ 200 211 “-” “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)” “-” “127.0.0.1:8081″ “200” “0.001”
115.29.113.101 – – [29/Jul/2014:20:54:22 +0800] “GET / HTTP/1.1″ 200 211 “-” “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)” “-” “127.0.0.1:8081″ “200” “0.005”
112.124.127.53 – – [29/Jul/2014:20:56:49 +0800] “GET / HTTP/1.1″ 200 211 “-” “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)” “-” “127.0.0.1:8081″ “200” “0.002”
112.124.127.44 – – [29/Jul/2014:20:59:20 +0800] “GET / HTTP/1.1″ 200 211 “-” “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)” “-” “127.0.0.1:8081″ “200” “0.002”
115.29.113.101 – – [29/Jul/2014:20:59:22 +0800] “GET / HTTP/1.1″ 200 211 “-” “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)” “-” “127.0.0.1:8081″ “200” “0.002”

三、分析nginx日志

3.1打印响应时间并且去除引号

cat website.access.log| awk ‘{print $(NF)}’ | awk -F “\”” ‘{print $2′}>a.txt

3.2合并文件,将时间重新补上去

paste -d ” ” website.access.log  a.txt > b.txt

3.3查找响应时间大于1秒的url

cat b.txt |awk ‘($NF>1){print $6$7 ” ” $NF}’>c.txt

结果如下图
QQ图片20141027145344

声明: 本文采用  BY-NC-SA 协议进行授权. 转载请注明转自:  awk分析nginx日志里面的接口响应时间
标签:  awk,  cat,  Nginx

你可能感兴趣的:(nginx,awk,cat)