log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
124.89.86.210 - - [08/May/2020:17:52:20 +0800] “POST /*/****t/.json HTTP/1.1” 200 74 “-” “okhttp/3.12.1”
$remote_addr - 用户IP
$remote_user 用户信息
$time_local] 请求时间
$request 请求地址/接口
$status 请求状态
$body_bytes_sent nginx返回给客户端的响应体的字节数
cat access.log |awk ‘{sum+=$10} END {print sum/1024/1024/1024}’
$10是nginx字段bytes_sent 字段,根据自己的日志格式修改
body_bytes_sent 发送给客户端的字节数,不包括响应头的大小
bytes_sent 发送给客户端的字节数
计算最高带宽
cat $ACCESS_LOG|awk -F’[: ]’ ‘{a[$5":"$6]+=$14}END{for(i in a){print i,a[i]}}’|sort|awk ‘{a+=$2;if(NR%5==0){if(a>b){b=a;c=$1};a=0}}END{print c,b*8/300/1024/1024}’