概念:
-
uv(unique visitor):獨(dú)立訪客,將每個(gè)獨(dú)立上網(wǎng)電腦(以cookie為依據(jù))視為一位訪客,一天之內(nèi)(00:00-24:00),訪問您網(wǎng)站的訪客數(shù)量。一天之內(nèi)相同cookie的訪問只被計(jì)算1次
-
PV(頁(yè)面瀏覽量)是指用戶每次訪問網(wǎng)站時(shí)所產(chǎn)生的點(diǎn)擊量或頁(yè)面瀏覽量,記錄為1次。用戶對(duì)同一頁(yè)面的多次訪問,訪問量值累計(jì)
-
統(tǒng)計(jì)獨(dú)立ip:00:00-24:00內(nèi)相同ip地址只被計(jì)算一次,做網(wǎng)站優(yōu)化的朋友最關(guān)心這個(gè)
先聲明下環(huán)境,此次運(yùn)行的nginx版本1.7,后端tomcat運(yùn)行的是動(dòng)態(tài)交互程序(需進(jìn)行用戶認(rèn)證,如果是靜態(tài)頁(yè)面則抓不到cache值,$http_cookie是空值),就是這樣;
nginx日志文件配置
http?{ ??include????mime.types; ??default_type?application/octet-stream; ??log_format?main?'$remote_addr?-?[$time_local]?"$request"?' ????????????'?-?$status?"user_cookie:$guid"?'; ?#user_cookie為日志顯示字符,$guid為變量,具體內(nèi)容在下面定義,也可在日志格式里寫入$http_cookie?顯示完整的cookie內(nèi)容<br> ??sendfile????on; ??keepalive_timeout?65; ????upstream?backserver?{ ????ip_hash; ????server?1.1.2.2:8080; ????server?1.1.2.3:8080; } server?{ ????listen????80; ????server_name?localhost; ????#if?(?$http_cookie?~*?"(.*)$")?匹配所有內(nèi)容 ????if?(?$http_cookie?~*?"csid=([a-z0-9]*)"){ ????????set?$guid?$1; ????}??#只匹配csid字符信息,此處為正則表達(dá)式<br> ????access_log?logs/host.access.log?main; ?????location?~*?^(.*)$?{ ???????#limit_req?zone=allips?burst=1?nodelay; ? ???????proxy_pass?http://backserver; ???????proxy_set_header?host?$host; ???????proxy_set_header?x-real-ip?$remote_addr; ???????proxy_set_header?remote-host?$remote_addr; ???????proxy_set_header?x-forwarded-for?$proxy_add_x_forwarded_for; ???????client_max_body_size?8m; ???????} ????error_page??500?502?503?504?/50x.html; ????location?=?/50x.html?{ ??????root??html; ????} }
注:$http_cookie這個(gè)里面的值是一個(gè)一個(gè)cookie的值,中間以“;”分隔
日志輸出格式
192.168.40.2 – [02/nov/2016:15:44:35 +0800]? “get /wcm/app/main/refresh.jsp?r=1478072325778 http/1.1”? – 200 “user_cookie:7f00000122a5597c46607b1c0a7ec016”
192.168.40.2 – [02/nov/2016:15:44:35 +0800]? “get /webpic/w0201611/w020161102/w020161102566715167404.jpg http/1.1”? – 200 “user_cookie:7f00000122a5597c46607b1c0a7ec016”
119.255.31.109 – [02/nov/2016:15:44:36 +0800]? “get /wcm/app/main/refresh.jsp?r=1478072510132 http/1.1”? – 200 “user_cookie:7f000001237921be9237838aec65704d”
119.255.31.109 – [02/nov/2016:15:44:36 +0800]? “get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1”? – 200 “user_cookie:7f000001237921be9237838aec65704d”
192.168.40.2 – [02/nov/2016:15:44:37 +0800]? “get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1”? – 200 “user_cookie:7f00000123d3bf2345115eaac21f71e0”
192.168.40.2 – [02/nov/2016:15:44:37 +0800]? “get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1”? – 200 “user_cookie:7f00000123ef73896df98eda9950944e”
192.168.40.2 – [02/nov/2016:15:44:37 +0800]? “get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1”? – 200 “user_cookie:7f00000123fe0f9c397e1a8f0c4f044b”
192.168.40.2 – [02/nov/2016:15:44:37 +0800]? “get /wcm/app/main/refresh.jsp?r=1478072511427 http/1.1”? – 200 “user_cookie:7f00000123a465b7ea1de0af0ae671b7”
119.255.31.109 – [02/nov/2016:15:44:38 +0800]? “get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1”? – 200 “user_cookie:7f00000123d89b11302df80ae773c900”?
pv統(tǒng)計(jì)
可統(tǒng)計(jì)單個(gè)鏈接地址訪問量:
[root@localhost?logs]#?grep?index.shtml?host.access.log?|?wc?-l
總pv量:
[root@localhost?logs]#?awk?'{print?$6}'?host.access.log?|?wc?-l
獨(dú)立ip
[root@localhost?logs]#?awk?'{print?$1}'?host.access.log?|?sort?-r?|uniq?-c?|?wc?-l
uv統(tǒng)計(jì)
[root@localhost?logs]#?awk?'{print?$10}'?host.access.log?|?sort?-r?|uniq?-c?|wc?-l
cookie 測(cè)試頁(yè)面
關(guān)于種cookie,可以使用下面的html代碼,編輯,添加需要種的cookie
#index.html ?nbsp;html?public?"-//w3c//dtd?xhtml?1.0?transitional//en"?"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <meta><meta>?//為了方便測(cè)試,每10秒刷新一次頁(yè)面 <h1>test.test.com域測(cè)試</h1> 下面列出了該域的cookie<br><p> <script> document.cookie="guid=a1ud8e5512451111111111"; //種cookie,追加 document.cookie="city=beijing"; //種cookie,追加 document.write(document.cookie); //列出已經(jīng)存在的 </script></p>