aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_admin_telnet.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_admin_telnet.lua')
-rw-r--r--plugins/mod_admin_telnet.lua66
1 files changed, 42 insertions, 24 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index 5264c21b..0fcb96b3 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -236,6 +236,7 @@ function commands.help(session, data)
elseif section == "server" then
print [[server:version() - Show the server's version number]]
print [[server:uptime() - Show how long the server has been running]]
+ print [[server:memory() - Show details about the server's memory usage]]
print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]]
elseif section == "port" then
print [[port:list() - Lists all network ports prosody currently listens on]]
@@ -300,6 +301,26 @@ function def_env.server:shutdown(reason)
return true, "Shutdown initiated";
end
+local function human(kb)
+ local unit = "K";
+ if kb > 1024 then
+ kb, unit = kb/1024, "M";
+ end
+ return ("%0.2f%sB"):format(kb, unit);
+end
+
+function def_env.server:memory()
+ if not pposix.meminfo then
+ return true, "Lua is using "..collectgarbage("count");
+ end
+ local mem, lua_mem = pposix.meminfo(), collectgarbage("count");
+ local print = self.session.print;
+ print("Process: "..human((mem.allocated+mem.allocated_mmap)/1024));
+ print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)");
+ print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)");
+ return true, "OK";
+end
+
def_env.module = {};
local function get_hosts_set(hosts, module)
@@ -463,6 +484,25 @@ end
function def_env.hosts:add(name)
end
+local function session_flags(session, line)
+ line = line or {};
+ if session.cert_identity_status == "valid" then
+ line[#line+1] = "(secure)";
+ elseif session.secure then
+ line[#line+1] = "(encrypted)";
+ end
+ if session.compressed then
+ line[#line+1] = "(compressed)";
+ end
+ if session.smacks then
+ line[#line+1] = "(sm)";
+ end
+ if session.ip and session.ip:match(":") then
+ line[#line+1] = "(IPv6)";
+ end
+ return table.concat(line, " ");
+end
+
def_env.c2s = {};
local function show_c2s(callback)
@@ -498,14 +538,9 @@ function def_env.c2s:show(match_jid)
count = count + 1;
local status, priority = "unavailable", tostring(session.priority or "-");
if session.presence then
- status = session.presence:child_with_name("show");
- if status then
- status = status:get_text() or "[invalid!]";
- else
- status = "available";
- end
+ status = session.presence:get_child_text("show") or "available";
end
- print(" "..jid.." - "..status.."("..priority..")");
+ print(session_flags(session, { " "..jid.." - "..status.."("..priority..")" }));
end
end);
return true, "Total: "..count.." clients";
@@ -544,23 +579,6 @@ function def_env.c2s:close(match_jid)
return true, "Total: "..count.." sessions closed";
end
-local function session_flags(session, line)
- if session.cert_identity_status == "valid" then
- line[#line+1] = "(secure)";
- elseif session.secure then
- line[#line+1] = "(encrypted)";
- end
- if session.compressed then
- line[#line+1] = "(compressed)";
- end
- if session.smacks then
- line[#line+1] = "(sm)";
- end
- if session.conn and session.conn:ip():match(":") then
- line[#line+1] = "(IPv6)";
- end
- return table.concat(line, " ");
-end
def_env.s2s = {};
function def_env.s2s:show(match_jid)