适用格式
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
形如:
127.0.0.1 - - [08/Jul/2024:02:00:11 +0800] "GET /test HTTP/1.1" 200 153164 "-" "Go-http-client/1.1"
127.0.0.1 - - [08/Jul/2024:02:00:12 +0800] "GET /test HTTP/1.1" 200 153164 "-" "Go-http-client/1.1"
命令
执行如下命令即可输出QPS和平均带宽情况
cat access.log |awk 'BEGIN{str="Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec";split(str,x," ");for(i in x){mon[x[i]]=i}}{split($4,a,/:|\[|\//);count+=1;totalSize+=$10;if(NR==1){startTime=mktime(a[4]" "mon[a[3]]" "a[2]" "a[5]" "a[6]" "a[7])}}END{if(NR==FNR){endTime=mktime(a[4]" "mon[a[3]]" "a[2]" "a[5]" "a[6]" "a[7])};print "from:"strftime("%Y-%m-%d %H:%M:%S",startTime);print "end:"strftime("%Y-%m-%d %H:%M:%S",endTime);print "time span:"endTime-startTime"s","count:"count,"qps:"count/(endTime-startTime),"bw(Mbps):"totalSize/(endTime-startTime)/1000/1000*8}'
PS:可根据需要如tail -100000 access.log来执行
执行结果
time span:752763s count:33407976 qps:44.3805 bw(Mbps):111.542
分别为:处理时间跨度(秒),处理总条数,qps,带宽(Mbps)