Comparison

plugins/mod_admin_shell.lua @ 11931:c65d5da8e99a

mod_admin_shell: List collected metrics in module:info Lets you know what to look for with stats:show()
author Kim Alvefur <zash@zash.se>
date Wed, 24 Nov 2021 20:03:38 +0100
parent 11930:ec46f110ce1d
child 11932:92925f1320e7
comparison
equal deleted inserted replaced
11930:ec46f110ce1d 11931:c65d5da8e99a
43 local format_table = require "util.human.io".table; 43 local format_table = require "util.human.io".table;
44 44
45 local function capitalize(s) 45 local function capitalize(s)
46 if not s then return end 46 if not s then return end
47 return (s:gsub("^%a", string.upper):gsub("_", " ")); 47 return (s:gsub("^%a", string.upper):gsub("_", " "));
48 end
49
50 local function pre(prefix, str, alt)
51 if (str or "") == "" then return alt or ""; end
52 return prefix .. str;
53 end
54
55 local function suf(str, suffix, alt)
56 if (str or "") == "" then return alt or ""; end
57 return str .. suffix;
48 end 58 end
49 59
50 local commands = module:shared("commands") 60 local commands = module:shared("commands")
51 local def_env = module:shared("env"); 61 local def_env = module:shared("env");
52 local default_env_mt = { __index = def_env }; 62 local default_env_mt = { __index = def_env };
420 ["adhoc-provider"] = "Ad-hoc commands", 430 ["adhoc-provider"] = "Ad-hoc commands",
421 ["auth-provider"] = "Authentication provider", 431 ["auth-provider"] = "Authentication provider",
422 ["http-provider"] = "HTTP services", 432 ["http-provider"] = "HTTP services",
423 ["net-provider"] = "Network service", 433 ["net-provider"] = "Network service",
424 ["storage-provider"] = "Storage driver", 434 ["storage-provider"] = "Storage driver",
435 ["measure"] = "Legacy metrics",
436 ["metric"] = "Metrics",
425 }; 437 };
426 local item_formatters = { 438 local item_formatters = {
427 ["feature"] = tostring, 439 ["feature"] = tostring,
428 ["identity"] = function(ident) return ident.type .. "/" .. ident.category; end, 440 ["identity"] = function(ident) return ident.type .. "/" .. ident.category; end,
429 ["adhoc-provider"] = function(item) return item.name; end, 441 ["adhoc-provider"] = function(item) return item.name; end,
430 ["auth-provider"] = function(item) return item.name; end, 442 ["auth-provider"] = function(item) return item.name; end,
431 ["storage-provider"] = function(item) return item.name; end, 443 ["storage-provider"] = function(item) return item.name; end,
432 ["http-provider"] = function(item, mod) return mod:http_url(item.name); end, 444 ["http-provider"] = function(item, mod) return mod:http_url(item.name); end,
433 ["net-provider"] = function(item) return item.name; end, 445 ["net-provider"] = function(item) return item.name; end,
446 ["measure"] = function(item) return item.name .. " (" .. suf(item.conf and item.conf.unit, " ") .. item.type .. ")"; end,
447 ["metric"] = function(item)
448 return ("%s (%s%s)%s"):format(item.name, suf(item.mf.unit, " "), item.mf.type_, pre(": ", item.mf.description));
449 end,
434 }; 450 };
435 451
436 for host in hosts do 452 for host in hosts do
437 local mod = modulemanager.get_module(host, name); 453 local mod = modulemanager.get_module(host, name);
438 if mod.module.host == "*" then 454 if mod.module.host == "*" then