From 1ac4aed7cde1aec722542199e488bc537423adbf Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 24 Nov 2021 20:03:38 +0100 Subject: mod_admin_shell: List collected metrics in module:info Lets you know what to look for with stats:show() --- core/moduleapi.lua | 2 ++ plugins/mod_admin_shell.lua | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/core/moduleapi.lua b/core/moduleapi.lua index ab154742..40c091ad 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -531,6 +531,7 @@ function api:measure(name, stat_type, conf) -- an array of labels -- the prosody_ prefix is automatically added by statsmanager for legacy -- metrics. + self:add_item("measure", { name = name, type = stat_type, conf = conf }); return measure(stat_type, "mod_"..self.name.."/"..name, conf, fixed_label_key, fixed_label_value) end @@ -544,6 +545,7 @@ function api:metric(type_, name, unit, description, label_keys, conf) label_keys:append(orig_labels) end local mf = metric(type_, "prosody_mod_"..self.name.."/"..name, unit, description, label_keys, conf) + self:add_item("metric", { name = name, mf = mf }); if is_scoped then -- make sure to scope the returned metric family to the current host return mf:with_partial_label(self.host) diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua index f8f56528..ab7fbb70 100644 --- a/plugins/mod_admin_shell.lua +++ b/plugins/mod_admin_shell.lua @@ -47,6 +47,16 @@ local function capitalize(s) return (s:gsub("^%a", string.upper):gsub("_", " ")); end +local function pre(prefix, str, alt) + if (str or "") == "" then return alt or ""; end + return prefix .. str; +end + +local function suf(str, suffix, alt) + if (str or "") == "" then return alt or ""; end + return str .. suffix; +end + local commands = module:shared("commands") local def_env = module:shared("env"); local default_env_mt = { __index = def_env }; @@ -422,6 +432,8 @@ function def_env.module:info(name, hosts) ["http-provider"] = "HTTP services", ["net-provider"] = "Network service", ["storage-provider"] = "Storage driver", + ["measure"] = "Legacy metrics", + ["metric"] = "Metrics", }; local item_formatters = { ["feature"] = tostring, @@ -431,6 +443,10 @@ function def_env.module:info(name, hosts) ["storage-provider"] = function(item) return item.name; end, ["http-provider"] = function(item, mod) return mod:http_url(item.name); end, ["net-provider"] = function(item) return item.name; end, + ["measure"] = function(item) return item.name .. " (" .. suf(item.conf and item.conf.unit, " ") .. item.type .. ")"; end, + ["metric"] = function(item) + return ("%s (%s%s)%s"):format(item.name, suf(item.mf.unit, " "), item.mf.type_, pre(": ", item.mf.description)); + end, }; for host in hosts do -- cgit v1.2.3