通过nginx日志统计5分钟内所有项目的pv

#!/bin/bash
for file in `ls -l /nginx/  |grep ^- | awk '{print $9}'`
do
ori_log_path="/logs/nginx/$file.access.log"
date_stamp=`date -d "-5min" +%Y:%H:%M:%S`
day_stamp=`date +%d`
#抽出5分钟内的日志
log_num=$(awk -F '[/ "\\[]' -vnstamp="$date_stamp" -vdstamp="$day_stamp" '$7>=nstamp && $5==dstamp' ${ori_log_path}  |wc -l)
echo $log_num
#算行数
echo $ file $ {log_num}
done  

查看各个访问量:
1.根据访问IP统计UV
awk ‘{print $1}’ /var/log/nginx/access.log|sort | uniq -c |wc -l
2.统计访问URL统计PV
awk ‘{print $7}’ /var/log/nginx/access.log|wc -l
3.查询访问最频繁的URL
awk ‘{print $7}’ /var/log/nginx/access.log|sort | uniq -c |sort -n -k 1 -r|more
4.查询访问最频繁的IP
awk ‘{print $1}’ /var/log/nginx/access.log|sort | uniq -c |sort -n -k 1 -r|more
5.根据时间段统计查看日志
cat /var/log/nginx/access.log| sed -n ‘/14/Mar/2017:21/,/14/Mar/2017:22/p’|more

你可能感兴趣的:(shell)