Skip to content

Commit 6c30482

Browse files
committed
feat: 优化echart图表展示
feat: 优化管理数据文件列表 feat: 支持统计服务级别WAF数据汇总 feat: 优化代码注释 feat:事务日程调整
1 parent ca64066 commit 6c30482

24 files changed

+351
-333
lines changed

api/router/tl_ops_api_get_state.lua

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ local Router = function()
3636
end
3737
local service_list = cjson.decode(list_str)
3838

39-
4039
for service_name, nodes in pairs(service_list) do
4140
-- service级别cache
4241
local health_lock_cache = shared:get(tl_ops_utils_func:gen_node_key(tl_ops_constant_health.cache_key.lock, service_name))
@@ -62,12 +61,49 @@ local Router = function()
6261
limit_version_cache = 0 --"version cache nil"
6362
end
6463

64+
-- waf统计, service级别是包含了service下所有waf规则下的汇总统计
65+
local waf_api_count = cache_waf_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf_count.cache_key.service_counting_list, service_name, "api"))
66+
if not waf_api_count then
67+
waf_api_count = "{}"
68+
end
69+
70+
local waf_ip_count = cache_waf_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf_count.cache_key.service_counting_list, service_name, "ip"))
71+
if not waf_ip_count then
72+
waf_ip_count = "{}"
73+
end
74+
75+
local waf_cc_count = cache_waf_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf_count.cache_key.service_counting_list, service_name, "cc"))
76+
if not waf_cc_count then
77+
waf_cc_count = "{}"
78+
end
79+
80+
local waf_cookie_count = cache_waf_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf_count.cache_key.service_counting_list, service_name, "cookie"))
81+
if not waf_cookie_count then
82+
waf_cookie_count = "{}"
83+
end
84+
85+
local waf_header_count = cache_waf_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf_count.cache_key.service_counting_list, service_name, "header"))
86+
if not waf_header_count then
87+
waf_header_count = "{}"
88+
end
89+
90+
local waf_param_count = cache_waf_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf_count.cache_key.service_counting_list, service_name, "param"))
91+
if not waf_param_count then
92+
waf_param_count = "{}"
93+
end
94+
6595
cache_state.service[service_name] = {
6696
health_lock = health_lock_cache,
6797
health_version = health_version_cache,
6898
health_uncheck = health_uncheck_cache,
6999
limit_state = limit_state_cache,
70100
limit_version = limit_version_cache,
101+
waf_api_count = cjson.decode(waf_api_count),
102+
waf_ip_count = cjson.decode(waf_ip_count),
103+
waf_cc_count = cjson.decode(waf_cc_count),
104+
waf_cookie_count = cjson.decode(waf_cookie_count),
105+
waf_header_count = cjson.decode(waf_header_count),
106+
waf_param_count = cjson.decode(waf_param_count),
71107
}
72108
cache_state.service[service_name].nodes = { }
73109

@@ -226,7 +262,8 @@ local Router = function()
226262
cache_state.balance['count_interval'] = tl_ops_constant_balance_count.interval
227263

228264
-- waf相关
229-
265+
266+
230267
-- 其他
231268
-- cache_state.other['dict_keys'] = shared:get_keys(1024)
232269

api/router/tl_ops_api_get_store.lua

Lines changed: 46 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ local tl_ops_manage_env = require("tl_ops_manage_env")
1111
local cjson = require("cjson.safe");
1212
cjson.encode_empty_table_as_object(false)
1313

14+
local store_list = {
15+
"tl-ops-balance-api","tl-ops-balance-body","tl-ops-balance-cookie",
16+
"tl-ops-balance-header","tl-ops-balance-param","tl-ops-service",
17+
"tl-ops-health","tl-ops-plugins-manage","tl-ops-limit",
18+
"tl-ops-balance","tl-ops-waf","tl-ops-waf-api", "tl-ops-waf-ip",
19+
"tl-ops-waf-header","tl-ops-waf-param","tl-ops-waf-cookie","tl-ops-waf-cc",
20+
"tl-ops-auth","tl-ops-time-alert","tl-ops-ssl","tl-ops-page-proxy"
21+
}
1422

1523
-- 读取文件
1624
local read = function( filename )
@@ -40,225 +48,49 @@ local read = function( filename )
4048
end
4149

4250

43-
local Router = function()
44-
local api_content, api_size = read("tl-ops-balance-api.tlstore");
45-
if not api_content then
46-
api_content = {}
47-
end
48-
local body_content, body_size = read("tl-ops-balance-body.tlstore");
49-
if not body_content then
50-
body_content = {}
51-
end
52-
local cookie_content, cookie_size = read("tl-ops-balance-cookie.tlstore");
53-
if not cookie_content then
54-
cookie_content = {}
55-
end
56-
local header_content, header_size = read("tl-ops-balance-header.tlstore");
57-
if not header_content then
58-
header_content = {}
59-
end
60-
local param_content, param_size = read("tl-ops-balance-param.tlstore");
61-
if not param_content then
62-
param_content = {}
63-
end
64-
local service_content, service_size = read("tl-ops-service.tlstore");
65-
if not service_content then
66-
service_content = {}
67-
end
68-
local health_content, health_size = read("tl-ops-health.tlstore");
69-
if not health_content then
70-
health_content = {}
71-
end
72-
local plugins_manage_content, plugins_manage_size = read("tl-ops-plugins-manage.tlstore");
73-
if not plugins_manage_content then
74-
plugins_manage_content = {}
75-
end
76-
local limit_content, limit_size = read("tl-ops-limit.tlstore");
77-
if not limit_content then
78-
limit_content = {}
79-
end
80-
local balance_content, balance_size = read("tl-ops-balance.tlstore");
81-
if not balance_content then
82-
balance_content = {}
83-
end
84-
local waf_content, waf_size = read("tl-ops-waf.tlstore");
85-
if not waf_content then
86-
waf_content = {}
87-
end
88-
local waf_api_content, waf_api_size = read("tl-ops-waf-api.tlstore");
89-
if not waf_api_content then
90-
waf_api_content = {}
91-
end
92-
local waf_ip_content, waf_ip_size = read("tl-ops-waf-ip.tlstore");
93-
if not waf_ip_content then
94-
waf_ip_content = {}
95-
end
96-
local waf_cookie_content, waf_cookie_size = read("tl-ops-waf-cookie.tlstore");
97-
if not waf_cookie_content then
98-
waf_cookie_content = {}
99-
end
100-
local waf_param_content, waf_param_size = read("tl-ops-waf-param.tlstore");
101-
if not waf_param_content then
102-
waf_param_content = {}
103-
end
104-
local waf_header_content, waf_header_size = read("tl-ops-waf-header.tlstore");
105-
if not waf_header_content then
106-
waf_header_content = {}
107-
end
108-
local waf_cc_content, waf_cc_size = read("tl-ops-waf-cc.tlstore");
109-
if not waf_cc_content then
110-
waf_cc_content = {}
111-
end
112-
local auth, auth_size = read("tl-ops-auth.tlstore");
113-
if not auth then
114-
auth = {}
115-
end
116-
local time_alert, time_alert_size = read("tl-ops-time-alert.tlstore");
117-
if not time_alert then
118-
time_alert = {}
51+
local Router = function()
52+
ngx.req.read_body()
53+
local args = ngx.req.get_post_args()
54+
55+
local page = args.page
56+
if not page then
57+
page = 1
11958
end
120-
local time_alert, time_alert_size = read("tl-ops-time-alert.tlstore");
121-
if not time_alert then
122-
time_alert = {}
59+
page = tonumber(page)
60+
61+
local limit = args.limit
62+
if not limit then
63+
limit = #store_list
12364
end
65+
limit = tonumber(limit)
66+
67+
local start = (page - 1) * limit + 1
68+
local tail = page * limit
12469

125-
local res_data = {
126-
api = {
127-
id = 1,
128-
name = "tl-ops-balance-api.tlstore",
129-
size = api_size,
130-
version = #api_content/2,
131-
list = api_content,
132-
},
133-
body = {
134-
id = 1,
135-
name = "tl-ops-balance-body.tlstore",
136-
size = body_size,
137-
version = #body_content/2,
138-
list = body_content,
139-
},
140-
cookie = {
141-
id = 2,
142-
name = "tl-ops-balance-cookie.tlstore",
143-
size = cookie_size,
144-
version = #cookie_content/2,
145-
list = cookie_content,
146-
},
147-
header = {
148-
id = 3,
149-
name = "tl-ops-balance-header.tlstore",
150-
size = header_size,
151-
version = #header_content/2,
152-
list = header_content,
153-
},
154-
param = {
155-
id = 4,
156-
name = "tl-ops-balance-param.tlstore",
157-
size = param_size,
158-
version = #param_content/2,
159-
list = param_content,
160-
},
161-
service = {
162-
id = 5,
163-
name = "tl-ops-service.tlstore",
164-
size = service_size,
165-
version = #service_content/2,
166-
list = service_content,
167-
},
168-
health = {
169-
id = 6,
170-
name = "tl-ops-health.tlstore",
171-
size = health_size,
172-
version = #health_content,
173-
list = health_content,
174-
},
175-
limit = {
176-
id = 7,
177-
name = "tl-ops-limit.tlstore",
178-
size = limit_size,
179-
version = #limit_content/3,
180-
list = limit_content,
181-
},
182-
plugins_manage = {
183-
id = 8,
184-
name = "tl-ops-plugins-manage.tlstore",
185-
size = plugins_manage_size,
186-
version = #plugins_manage_content,
187-
list = plugins_manage_content,
188-
},
189-
balance = {
190-
id = 8,
191-
name = "tl-ops-balance.tlstore",
192-
size = balance_size,
193-
version = #balance_content,
194-
list = balance_content,
195-
},
196-
waf = {
197-
id = 9,
198-
name = "tl-ops-waf.tlstore",
199-
size = waf_size,
200-
version = #waf_content,
201-
list = waf_content,
202-
},
203-
waf_api = {
204-
id = 10,
205-
name = "tl-ops-waf-api.tlstore",
206-
size = waf_api_size,
207-
version = #waf_api_content,
208-
list = waf_api_content,
209-
},
210-
waf_ip = {
211-
id = 11,
212-
name = "tl-ops-waf-ip.tlstore",
213-
size = waf_ip_size,
214-
version = #waf_ip_content,
215-
list = waf_ip_content,
216-
},
217-
waf_cookie = {
218-
id = 12,
219-
name = "tl-ops-waf-cookie.tlstore",
220-
size = waf_cookie_size,
221-
version = #waf_cookie_content,
222-
list = waf_cookie_content,
223-
},
224-
waf_param = {
225-
id = 13,
226-
name = "tl-ops-waf-param.tlstore",
227-
size = waf_param_size,
228-
version = #waf_param_content,
229-
list = waf_param_content,
230-
},
231-
waf_header = {
232-
id = 14,
233-
name = "tl-ops-waf-header.tlstore",
234-
size = waf_header_size,
235-
version = #waf_header_content,
236-
list = waf_header_content,
237-
},
238-
waf_cc = {
239-
id = 15,
240-
name = "tl-ops-waf-cc.tlstore",
241-
size = waf_cc_size,
242-
version = #waf_cc_content,
243-
list = waf_cc_content,
244-
},
245-
auth = {
246-
id = 16,
247-
name = "tl-ops-auth.tlstore",
248-
size = auth_size,
249-
version = #auth,
250-
list = auth,
251-
},
252-
time_alert = {
253-
id = 17,
254-
name = "tl-ops-time-alert.tlstore",
255-
size = time_alert_size,
256-
version = #time_alert,
257-
list = time_alert,
258-
}
70+
local res_data = {
71+
count = #store_list,
72+
list = {}
25973
}
26074

75+
for index, value in ipairs(store_list) do
76+
if index >= start and index <= tail then
77+
local name = value .. ".tlstore";
78+
local content, size = read(name);
79+
if not content then
80+
content = {}
81+
end
82+
table.insert(res_data.list, {
83+
id = index,
84+
name = value .. ".tlstore",
85+
size = size,
86+
version = "暂不统计",
87+
list = content,
88+
})
89+
end
90+
end
91+
26192
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
26293
end
263-
94+
95+
26496
return Router

bin/install_centeros.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
66
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
77
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
88
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
9-
TL_OPS_VER="v3.4.0"
9+
TL_OPS_VER="v3.4.1"
1010

1111
echo_msg(){
1212
cur_time=$(date "+%Y-%m-%d %H:%M:%S")

bin/install_ubuntu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
66
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
77
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
88
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
9-
TL_OPS_VER="v3.4.0"
9+
TL_OPS_VER="v3.4.1"
1010

1111
echo_msg(){
1212
cur_time=$(date "+%Y-%m-%d %H:%M:%S")

constant/tl_ops_constant_waf_count.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local tl_ops_constant_waf_count = {
33
cache_key = {
44
-- 临时字段
55
lock = "tl_ops_waf_count_lock",
6-
node_req_succ = "tl_ops_waf_node_req_succ", -- 以节点单位命中次数次数 int
6+
service_req_succ = "tl_ops_waf_service_req_succ", -- 以服务为单位命中次数次数 int
77
ip_req_succ = "tl_ops_waf_ip_req_succ", -- 以ip规则命中次数次数 int
88
api_req_succ = "tl_ops_waf_api_req_succ", -- 以api规则命中次数次数 int
99
cc_req_succ = "tl_ops_waf_cc_req_succ", -- 以cc规则命中次数次数 int
@@ -12,7 +12,7 @@ local tl_ops_constant_waf_count = {
1212
param_req_succ = "tl_ops_waf_param_req_succ", -- 以param规则命中次数次数 int
1313

1414
-- 持久化字段
15-
node_counting_list = "tl_ops_waf_node_counting_list", -- 以ip规则单位,周期内统计次数集合 list
15+
service_counting_list = "tl_ops_waf_service_counting_list", -- 以服务单位,周期内统计次数集合 list
1616
ip_counting_list = "tl_ops_waf_ip_counting_list", -- 以ip规则单位,周期内统计次数集合 list
1717
api_counting_list = "tl_ops_waf_api_counting_list", -- 以api规则单位,周期内统计次数集合 list
1818
cc_counting_list = "tl_ops_waf_cc_counting_list", -- 以cc规则为单位,周期内统计次数集合 list

0 commit comments

Comments
 (0)