首页 > 代码库 > awk 分析web日志(页面执行时间)
awk 分析web日志(页面执行时间)
log_format main ‘$remote_addr - $remote_user [$time_local] $request ‘
‘"$status" $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for" $request_time‘;
access_log /var/log/nginx/access.log main buffer=32k;
222.83.181.42 - - [09/Oct/2010:04:04:03 +0800] GET /pages/international/tejia.php HTTP/1.1 "200" 15708 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Sicent; WoShiHoney.B; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" "-" 0.037
按照空格分隔的话,最后一个字段[0.037] 是页面执行时间,第7个字段 是页面访问地址。
awk ‘BEGIN{
print "Enter log file:";
getline logs;
#logs="/var/log/nginx/access.log-20101008";
OFMT="%.3f";
while(getline < logs)
{
split($7,atmp,"?");
aListNum[atmp[1]]+=1;
aListTime[atmp[1]]+=$NF;
ilen++;
}
close(logs);
print "\r\ntotal:",ilen,"\r\n======================================\r\n";
for(k in aListNum)
{
print k,aListNum[k],aListTime[k]/aListNum[k] | "sort -r -n -k3";
}
}‘
awk 分析web日志(页面执行时间)