-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstats_simple_demo.conf
38 lines (32 loc) · 1.24 KB
/
stats_simple_demo.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
lua_package_path '/path/to/lua-resty-stats/lib/?.lua;/path/to/lua-resty-stats/lib/?/init.lua;/path/to/lua-resty-stats/view/?.lua;;';
# stats config
init_worker_by_lua_block {
require("resty.core")
local stats = require("resty.stats")
-- add the default stats that named "stats_host"
stats.add_def_stats()
-- the general stats"s config
local update = {["$inc"]= {count=1, ["hour_cnt.$hour"]=1, ["status.$status"]=1,
["req_time.all"]="$request_time", ["req_time.$hour"]="$request_time"}}
-- stats by uri
stats.add_stats_config("stats_uri",
{selector={date="$date",key="$host:$uri"}, update=update,index_keys={"date", "key"}})
local mongo_cfg = {host="127.0.0.1", port=27017, dbname="ngx_stats"}
local flush_interval = 5 -- second
local retry_interval = 0.2 -- second
-- init stats and start flush timer.
stats.init(mongo_cfg, flush_interval, retry_interval)
}
log_by_lua_block {
local stats = require("resty.stats")
stats.log("stats_uri")
stats.log("stats_host")
}
server {
listen 2000;
server_name localhost;
location /stats {
set $template_root /path/to/lua-resty-stats/view;
content_by_lua_file '/path/to/lua-resty-stats/view/main.lua';
}
}