diff options
author | Matthew Wild <mwild1@gmail.com> | 2013-05-16 10:47:22 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2013-05-16 10:47:22 +0100 |
commit | f6f9dae378f74717d52ba03e880d84cca606d833 (patch) | |
tree | 0a726a464638d99727be54b935e6f299fd438e68 /plugins/mod_admin_telnet.lua | |
parent | e76f13c5d29bf4cac7a244eab77a354638f8823b (diff) | |
download | prosody-f6f9dae378f74717d52ba03e880d84cca606d833.tar.gz prosody-f6f9dae378f74717d52ba03e880d84cca606d833.zip |
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Diffstat (limited to 'plugins/mod_admin_telnet.lua')
-rw-r--r-- | plugins/mod_admin_telnet.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index 753e2d2c..b67ba576 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) |