目前环境上的日志格式配置
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" ';
$remote_addr 客户端IP地址
$remote_user 记录客户端用户,有认证的时候才显示
$time_local
$request 请求的URL和协议
$status 记录返回HTTP请求的状态
$body_bytes_sent 发送给客户端的字节数,不包含响应头
$http_referer 记录从哪个也蜜饯链接访问过来的
$http_user_agent
$http_x_forwarded_for HTTP请求端真实的IP
$request_time 请求处理时间,单位s 进度ms
$upstream_response_time 应用程序响应时间,向后端服务建立连接到关闭连接的总时间
统计独立IP数
awk '{print $1}' access.log |sort -r|uniq -c|wc -l
总PV量
awk '{print $7}' access.log|wc -l
UV
awk '{print $11}' access.log|sort -r|uniq -c|wc -l
统计访问量前20的IP
awk '{print $1}' access.log|sort|uniq -c|sort -nr|head -20
访问最多的页面
awk '{print $7}' access.log|sort|uniq -c|sort -nr|head -20
处理时间request_time
需要新增request_time 到log_format 中,比如加到最后
查看请求处理时间大于5s的URL
awk '{if ( $NF>5) print $NF,$7,$1}' access.log|sort -nr