Using Nginx log file to count all IP and PV, list the top 10 IP, take confluence Knowledge base system as an example:
Nginx log file is/var/log/nginx/access.log
# wc -l /var/log/nginx/access.log 95146 /var/log/nginx/access.log
Shell script:
# vim accessnum.sh #!/bin/bash#writen by Gavin Zhao#This shell will print how many users access your server by webawk ‘/itks/ {print $1}‘ /var/log/nginx/access.log | sort -rn | uniq -c | sort -rn | awk ‘{$2 ~ /10./ && $2!="10.1.46.189" && (tot=tot+$0)};END{print NR,tot}‘ > /root/script/num.txt 2> /dev/nullip=`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
One shell per day (vii) IP and PV for the statistics site