How does awk analyze web logs
This article shows you how awk analyzes web logs, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
The editor mainly talks about how to get the execution time quickly by analyzing the log through awk.
I. web log file format
The code is as follows:
222.83.181.42-[09/Oct/2010:04:04:03 + 0800] GET / pages/international/tejia.php HTTP/1.1 "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
Separated by spaces, the last field [0.037] is the page execution time, and the seventh field is the page access address.
Second, execute the code
The code is as follows:
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"; } }' 结果:
Performance:
422780 logs, the statistical completion speed is about 5 seconds.
The above is how awk analyzes web logs. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.