通过Shell统计PV和UV

PV、UV是网站分析中最基础、最常见的指标。
PV即PageView,网站浏览量,指页面的浏览次数,用以衡量网站用户访问的网页数量。用户没打开一个页面便记录1次PV,多次打开同一页面则浏览量累计;
UV即UniqueVistor,独立访客数,指1天内访问某站点的人数,以cookie为依据。1天内同一访客的多次访问只计为1个访客;
通过linux的shell可以快速的统计pv和uv。

nginx log格式如下:

log_format  pushlogs  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent $upstream_response_time $request_time "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for "$server_name" "$http_host" "$xxx_f_push" "$xxx_cookie"';

通过cookie来确定用户身份,cookie是$xxx_cookie

#pv
less abc.log | awk '{print $(NF-1),$NF}' |awk '{print $1}' | sort -nr | uniq -c  > /tmp/pv.txt

#uv
less abc.log | awk '{print $(NF-1),$NF}' | sort | uniq  | awk '{print $1}' |  uniq -c | sort -nr > /tmp/uv.txt 

除非注明,本博客文章均为原创,转载请以链接形式标明本文地址
本文地址: http://blog.cnwyhx.com/stat_pv_uv_by_shell

原文地址:https://www.cnblogs.com/clarke/p/5447346.html