通过Nginx日志文件统计出所有的IP和PV,列出排名前10的IP,以confluence知识库系统为例:
Nginx日志文件为/var/log/Nginx/access.log
shell脚本:
- # vim accessnum.sh
- #!/bin/bash
- #writen by Gavin Zhao
- #This shell will print how many users access your server by web
- awk '/itks/ {print $1}' /var/log/Nginx/access.log | sort -rn | uniq -c | sort -rn | awk '{$2 ~ /10./ && $2!="10.1.46.189" && (tot=to
- t+$0)};END{print NR,tot}' > /root/script/num.txt 2> /dev/null
- ip=`awk '{print $1}' /root/script/num.txt`
- pv=`awk '{print $2}' /root/script/num.txt`
- echo "截止到目前IT知识库的总访问量:$pv"
- echo "截止到目前IT知识库的总访问IP数:$ip"
- echo "排名前10的IP如下:"
- awk '/itks/ {print $1}' /var/log/Nginx/access.log | sort -rn | uniq -c | sort -rn | awk ' $2 ~ /10./ && $2 !~ /10.1.46.189|10.1.116.
- 4/ && NR<=12 {print $2}'
- chmod +x accessnum.sh