[关闭]
@42withyou 2015-03-01T09:58:06.000000Z 字数 3658 阅读 420

红包

Justering


  1. #!/bin/bash
  2. # 统计某天某个时间段内各 HTTP status codes 的出现次数和比例,已排除静态文件
  3. # Example: 统计 2015-2-19 20:30-20:35 的数据
  4. # 哎 才想到还可以根据 ip 统计 uv...
  5. # ./tongji.sh hongbao-access.log 19/Feb/2015 20 30 20 35
  6. # |200|66674|0.631|
  7. # |302|33013|0.312|
  8. # |304|4564|0.043|
  9. # |499|895|0.008|
  10. # |404|268|0.003|
  11. # |206|217|0.002|
  12. # |502|24|0.000|
  13. # |400|2|0.000|
  14. # 使用|划分是为了方便 markdown 使用,markdown 下在结果上加上下面两行表格就出来了
  15. #| code | pv | percent |
  16. #| ---- | ----- | ----|
  17. file=$1
  18. year=$2
  19. h_start=$3
  20. m_start=$4
  21. h_end=$5
  22. m_end=$6
  23. awk -F ' ' '
  24. {
  25. split(substr($4, 2), time, ":");
  26. if (index($8, "/styles/") != 0 || index($8, "/uploads/") != 0) {
  27. next;
  28. }
  29. if (time[1] == "'"$year"'" && ((time[2] >= "'"$h_start"'" && time[3] >= "'"$m_start"'") || (time[2] <= "'"$h_end"'" && time[3] <= "'"$m_end"'"))) {
  30. rec[$9] += 1;
  31. count += 1;
  32. }
  33. }
  34. END {
  35. for(i in rec) {
  36. printf("|%s|%d|%.3f|\n", i, rec[i], rec[i] / count);
  37. }
  38. }' $file |
  39. sort -n -r -t '|' -k 3
  40. exit 0

全部数据

  1. awk '{if (index($8, "/styles/") != 0 || index($8, "/uploads/") != 0) {next;} rec[$9] += 1;count += 1;}END{for(i in rec) printf("|%s|%d|%.3f|\n", i, rec[i], rec[i] / count);}' hongbao-access.log | sort -n -r -t '|' -k 3
code count percent mean
200 1171871 0.617 OK
302 568213 0.299 Found
304 72392 0.038 Not Modified
502 51539 0.027 Bad Gateway
499 31253 0.016 Token required (Esri)
206 2747 0.001 Partial Content
404 1747 0.001 Not Found
500 35 0.000 Internal Server Error
408 9 0.000 Request Timeout
400 2 0.000 Bad Request

大年三十

all day

code pv percent
200 375980 0.512
302 161299 0.220
502 141832 0.193
499 31463 0.043
304 21607 0.029
206 1059 0.001
404 463 0.001
408 4 0.000
500 3 0.000
400 2 0.000

8:30-9:30

code count percent
200 244490 0.459
502 137234 0.258 / 0.027 主要问题在这
302 112389 0.211 / 0.299
499 22479 0.042 / 0.016
304 15014 0.028 / 0.038
206 687 0.001
404 271 0.001
408 2 0.000
500 1 0.000

8:30-8:35

code pv percent
502 123939 0.367
302 107939 0.320
200 87747 0.260
499 17651 0.052
404 121 0.000
304 25 0.000
500 1 0.000
408 1 0.000

初一

全天

code count percent
200 371246 0.664
302 153386 0.274
304 23156 0.041
502 5795 0.010
499 3940 0.007
206 942 0.002
404 906 0.002
500 2 0.000
408 2 0.000

8:30-9:30

code count percent
200 276393 0.665
302 111510 0.268
304 17160 0.041
502 5795 0.014
499 3443 0.008
206 746 0.002
404 620 0.001
500 2 0.000
408 2 0.000

8:30-8:35

code pv percent / 全天 / 全部
502 123939 0.367 / 0.010 / 0.027
302 107939 0.320 / 0.274 / 0.299
200 87747 0.260 / 0.664 / 0.617
499 17651 0.052 / 0.007 / 0.016
404 121 0.000 / 0.002 / 0.001
304 25 0.000 / 0.041 / 0.038
500 1 0.000 / 0.000 / 0.000
408 1 0.000 / 0.000 / 0.000
206 0 0.000 / 0.002 / 0.001

See: List of HTTP status codes.


访问前20的链接,重点优化

  1. cat hongbao-access.log | awk -F ' ' '{if(length($11) != 3) rec[$11] += 1;count+=1}END{for(i in rec){printf("|%s|%d|%.3f\n", i, rec[i], rec[i] / count)}}' | sort -n -r -t '|' -k 3 | head -n 20
link count percent
"http://mp.weixin.qq.com/mp/redirect?url= http://hongbao.cydf.org.cn/hongbao/latest_hongbao? user_openid=10000000%23rd" 291725 0.154
"http://hb.cydf.org.cn/hongbao/index?id=1146" 149184 0.079
"http://hb.cydf.org.cn/pay/index" 87319 0.046
"http://hb.cydf.org.cn/" 71655 0.038
"http://hb.cydf.org.cn/hongbao?id=1140" 61895 0.033
"http://hb.cydf.org.cn/Dashboard/allocate" 59406 0.031
"http://hb.cydf.org.cn/dashboard/allocate" 48458 0.026
"http://hb.cydf.org.cn/hongbao?id=1141" 43556 0.023
"http://hongbao.cydf.org.cn/hongbao?id=1138" 27531 0.015
"http://hongbao.cydf.org.cn/pay/index" 18875 0.010
"http://hb.cydf.org.cn/hongbao?id=1137" 17025 0.009
"http://hongbao.cydf.org.cn/Dashboard/allocate" 13165 0.007
"http://hb.cydf.org.cn/dashboard/received" 9341 0.005
"http://hongbao.cydf.org.cn/hongbao?id=1140" 8885 0.005
"http://hongbao.cydf.org.cn/" 8657 0.005
"http://hb.cydf.org.cn/index/topten" 4954 0.003
"http://hongbao.cydf.org.cn/hongbao?id=1138&team_id=7& from=timeline&isappinstalled=0" 3205 0.002
"http://hb.cydf.org.cn/Dashboard/allocate_success? project_money_21=12.00& project_money_20=12.31&project_money_23=0.00& from=groupmessage&isappinstalled=0" 3089 0.002
"http://hb.cydf.org.cn/hongbao?id=1140&from=timeline&isappinstalled=0" 2065 0.001
"http://hongbao.cydf.org.cn/dashboard/received" 2010 0.001

独立ip

  1. cat hongbao-access.log | awk -F ' ' '{print $1}' | sort -u | wc
  2. 71276 71276 1022946
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注