diff --git a/plugins/webstats/conf/init.sql b/plugins/webstats/conf/init.sql index c7b548262..63a1219ca 100644 --- a/plugins/webstats/conf/init.sql +++ b/plugins/webstats/conf/init.sql @@ -31,6 +31,7 @@ CREATE INDEX method_idx ON web_logs (`method`); CREATE INDEX status_code_idx ON web_logs (`status_code`); CREATE INDEX request_time_idx ON web_logs (`request_time`); CREATE INDEX is_spider_idx ON web_logs (`is_spider`); +CREATE INDEX body_length_idx ON web_logs (`body_length`); CREATE INDEX all_union_idx ON web_logs (`time`,`ip`,`method`,`status_code`,`request_time`,`is_spider`); @@ -84,6 +85,7 @@ CREATE TABLE `request_stat`( `status_402` INTEGER DEFAULT 0, `status_403` INTEGER DEFAULT 0, `status_404` INTEGER DEFAULT 0, + `status_499` INTEGER DEFAULT 0, `http_get` INTEGER DEFAULT 0, `http_post` INTEGER DEFAULT 0, `http_put` INTEGER DEFAULT 0, diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 35635fceb..860f615d2 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -2263,7 +2263,7 @@ function wsTableLogRequest(page){ var rdata = $.parseJSON(rdata.data); var list = ''; var data = rdata.data.data; - console.log(data); + // console.log(data); if (data.length > 0){ for(i in data){ diff --git a/plugins/webstats/lua/webstats_common.lua b/plugins/webstats/lua/webstats_common.lua index 814d650cd..e6670acb7 100644 --- a/plugins/webstats/lua/webstats_common.lua +++ b/plugins/webstats/lua/webstats_common.lua @@ -616,7 +616,32 @@ function _M.statistics_request(self, ip, is_spider, body_length) -- 计算pv uv local pvc = 0 local uvc = 0 + local request_header = ngx.req.get_headers() + if not is_spider and ngx.status == 200 and body_length > 0 then + local ua = '' + if request_header['user-agent'] then + ua = string.lower(request_header['user-agent']) + end + + pvc = 1 + if ua then + local today = ngx.today() + local uv_token = ngx.md5(ip .. ua .. today) + if not cache:get(uv_token) then + uvc = 1 + cache:set(uv_token,1, self:get_end_time()) + end + end + end + return pvc, uvc +end +-- 仅计算GET +function _M.statistics_request_old(self, ip, is_spider, body_length) + -- 计算pv uv + local pvc = 0 + local uvc = 0 + local method = ngx.req.get_method() if not is_spider and method == 'GET' and ngx.status == 200 and body_length > 512 then local ua = '' if request_header['user-agent'] then diff --git a/plugins/webstats/lua/webstats_log.lua b/plugins/webstats/lua/webstats_log.lua index 148f3b309..693424770 100644 --- a/plugins/webstats/lua/webstats_log.lua +++ b/plugins/webstats/lua/webstats_log.lua @@ -260,7 +260,7 @@ log_by_lua_block { end end - if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451", tostring(status_code), "jo") then + if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451,499", tostring(status_code), "jo") then local field = "status_"..status_code request_stat_fields = request_stat_fields .. ","..field.."="..field.."+1" end @@ -392,7 +392,7 @@ log_by_lua_block { end end - if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451", tostring(status_code), "jo") then + if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451,499", tostring(status_code), "jo") then local field = "status_"..status_code request_stat_fields[field] = 1 end