nginx并发查看UV、PV统计脚本

开启nginx访问日志,日志路径为/var/log/nginx/access.log,编写脚本:

log_path=/var/log/nginx/access.log

echo -e '\033[32m ====URL访问排名====  \033[0m'
awk '{print $7}' $log_path|sort | uniq -c |sort -n -k 1 -r|head -n 10

echo
echo -e '\033[32m ====IP访问排名====  \033[0m'
awk '{print $1}' $log_path|sort | uniq -c |sort -n -k 1 -r|head -n 10

echo
echo -e '\033[32m ====每分钟并发数排名====  \033[0m'
sed -n '/2019:19:00/,/2019:23:00/p' $log_path |  awk  '{a[substr($4,9,10)]+=1} END{for(i in a) printf "%s %s\n",i,a[i]}'  | sort -k 2 -n -r | head -n 20

echo
echo -e '\033[32m ===TCP链接数量====  \033[0m'
echo '443端口(静态页)'
netstat -pnt | grep :443 | wc -l
echo '1235端口(API接口)'
netstat -pnt | grep :1235 | wc -l

echo
echo -e '\033[32m UV:  \033[0m'
awk '{print $1}' $log_path|sort | uniq -c |wc -l

echo -e '\033[32m PV: \033[0m'
awk '{print $7}' $log_path|wc -l

执行输出

====URL访问排名====  
  61714 /tgglApi/xxx/login
  27538 /tgglApi/course/xxx?levelId=1&actionId=14&_t=1555035486
  13453 /tgglApi/student/xxx/22821/13/10


 ====IP访问排名====  
  94768 124.78.91.88
  13453 220.200.62.33
   5274 175.162.109.46
   2921 165.225.116.128
   2460 42.84.253.26
   2446 42.185.69.177
   1799 123.191.165.196
   1644 13.70.0.121
   1356 14.103.113.205
   1046 183.63.90.59

 ====每分钟并发数排名====  
2019:11:22 12899
2019:11:21 12343
2019:11:23 5219
2019:11:17 4208
2019:11:16 4086
2019:10:33 4041
2019:10:05 4041
2019:11:20 3971
2019:10:34 3899
2019:10:11 3758
2019:10:35 3408
2019:10:32 3408
2019:10:06 3272
2019:10:16 3214
2019:11:19 2992
2019:10:17 2722
2019:11:24 2211
2019:10:26 2103
2019:10:10 1494
2019:10:12 1380

 ===TCP链接数量====  
443端口(静态页)
107
1235端口(API接口)
79

 UV:  
1352
 PV: 
155467

1 条评论

[/0o0] [..^v^..] [0_0] [T.T] [=3-❤] [❤.❤] [^v^] [-.0] [!- -] [=x=] [→_→] [><] 更多 »
昵称
  1. from 233.name Google Chrome 71 Google Chrome 71 Windows 10 Windows 10

    [0_0]