From b373c5e17b7c3aceb15cdecef5c64775725b533e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Nov 2024 10:29:38 +0000 Subject: [Feature] Show stats in rspamadm --- lualib/rspamadm/fuzzy_stat.lua | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'lualib') diff --git a/lualib/rspamadm/fuzzy_stat.lua b/lualib/rspamadm/fuzzy_stat.lua index ef8a5de08..b9af35e22 100644 --- a/lualib/rspamadm/fuzzy_stat.lua +++ b/lualib/rspamadm/fuzzy_stat.lua @@ -59,7 +59,23 @@ local function add_data(target, src) if type(v.extensions.name) == 'string' then target.name = v.extensions.name end + if type(v.extensions.email) == 'string' then + target.email = v.extensions.email + end + if type(v.extensions.ratelimit) == 'table' then + if not target.ratelimit then + target.ratelimit = {} + end + -- Passed as {burst = x, rate = y} + target.ratelimit.limit = v.extensions.ratelimit + end + end + elseif k == 'ratelimit' then + if not target.ratelimit then + target.ratelimit = {} end + -- Ratelimit is passed as {cur = count, last = time} + target.ratelimit.cur = v end end end @@ -301,7 +317,8 @@ return function(args, res) for _, key in ipairs(sorted_keys) do local key_stat = key.data if key_stat.name then - print(string.format('Key id: %s, name: %s', key.key, key_stat.name)) + print(string.format('Key id: %s, name: %s (email: %s)', key.key, key_stat.name, + key_stat.email or 'unknown')) else print(string.format('Key id: %s', key.key)) end @@ -332,6 +349,16 @@ return function(args, res) end end + if key_stat.ratelimit then + print('') + print('\tRatelimit stat:') + print(string.format('\tLimit: %s (%s leak rate)', + print_num(key_stat.ratelimit.limit.burst), print_num(key_stat.ratelimit.limit.rate))) + print(string.format('\tCurrent: %s (%s last)', + print_num(key_stat.ratelimit.cur), os.date('%c', key_stat.ratelimit.last))) + print('') + end + print('') end end -- cgit v1.2.3 From 4d9be4459247864c90c36346d141678e51bd3f3c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Nov 2024 10:52:38 +0000 Subject: [Minor] Improve format --- lualib/rspamadm/fuzzy_stat.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lualib') diff --git a/lualib/rspamadm/fuzzy_stat.lua b/lualib/rspamadm/fuzzy_stat.lua index b9af35e22..011f9d37c 100644 --- a/lualib/rspamadm/fuzzy_stat.lua +++ b/lualib/rspamadm/fuzzy_stat.lua @@ -352,8 +352,8 @@ return function(args, res) if key_stat.ratelimit then print('') print('\tRatelimit stat:') - print(string.format('\tLimit: %s (%s leak rate)', - print_num(key_stat.ratelimit.limit.burst), print_num(key_stat.ratelimit.limit.rate))) + print(string.format('\tLimit: %s (%.2f per hour leak rate)', + print_num(key_stat.ratelimit.limit.burst), (key_stat.ratelimit.limit.rate or 0.0) * 3600)) print(string.format('\tCurrent: %s (%s last)', print_num(key_stat.ratelimit.cur), os.date('%c', key_stat.ratelimit.last))) print('') -- cgit v1.2.3 From 4d78f29a7b822231bce8d557f18b644ed5deaf73 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Nov 2024 11:04:53 +0000 Subject: [Minor] Some display/adding fixes --- lualib/rspamadm/fuzzy_stat.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lualib') diff --git a/lualib/rspamadm/fuzzy_stat.lua b/lualib/rspamadm/fuzzy_stat.lua index 011f9d37c..c65a1a477 100644 --- a/lualib/rspamadm/fuzzy_stat.lua +++ b/lualib/rspamadm/fuzzy_stat.lua @@ -72,10 +72,16 @@ local function add_data(target, src) end elseif k == 'ratelimit' then if not target.ratelimit then - target.ratelimit = {} + target.ratelimit = { + cur = { + last = 0, + count = 0 + } + } end -- Ratelimit is passed as {cur = count, last = time} - target.ratelimit.cur = v + target.ratelimit.cur.count = v.cur + target.ratelimit.cur.count + target.ratelimit.cur.last = math.max(v.last, target.ratelimit.cur.last) end end end @@ -355,7 +361,7 @@ return function(args, res) print(string.format('\tLimit: %s (%.2f per hour leak rate)', print_num(key_stat.ratelimit.limit.burst), (key_stat.ratelimit.limit.rate or 0.0) * 3600)) print(string.format('\tCurrent: %s (%s last)', - print_num(key_stat.ratelimit.cur), os.date('%c', key_stat.ratelimit.last))) + print_num(key_stat.ratelimit.cur.count), os.date('%c', key_stat.ratelimit.cur.last))) print('') end -- cgit v1.2.3 From 590949b11bc4ed5c1530b35227fc6fd17cf18dd6 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Nov 2024 11:10:17 +0000 Subject: [Minor] Do not fail on empty limits --- lualib/rspamadm/fuzzy_stat.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lualib') diff --git a/lualib/rspamadm/fuzzy_stat.lua b/lualib/rspamadm/fuzzy_stat.lua index c65a1a477..c5b6ec384 100644 --- a/lualib/rspamadm/fuzzy_stat.lua +++ b/lualib/rspamadm/fuzzy_stat.lua @@ -64,7 +64,12 @@ local function add_data(target, src) end if type(v.extensions.ratelimit) == 'table' then if not target.ratelimit then - target.ratelimit = {} + target.ratelimit = { + cur = { + last = 0, + count = 0 + }, + } end -- Passed as {burst = x, rate = y} target.ratelimit.limit = v.extensions.ratelimit @@ -76,7 +81,7 @@ local function add_data(target, src) cur = { last = 0, count = 0 - } + }, } end -- Ratelimit is passed as {cur = count, last = time} -- cgit v1.2.3