Comparison

plugins/mod_admin_telnet.lua @ 5672:0c68cea74d5d

mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
author Matthew Wild <mwild1@gmail.com>
date Thu, 16 May 2013 10:47:22 +0100
parent 5665:da1881e1b35b
child 5674:ebdbf4cf0b2f
child 5769:f6ea5b3739c9
comparison
equal deleted inserted replaced
5671:d5059e73db53 5672:0c68cea74d5d
234 print [[user:delete(jid) - Permanently remove the specified user account]] 234 print [[user:delete(jid) - Permanently remove the specified user account]]
235 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] 235 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
236 elseif section == "server" then 236 elseif section == "server" then
237 print [[server:version() - Show the server's version number]] 237 print [[server:version() - Show the server's version number]]
238 print [[server:uptime() - Show how long the server has been running]] 238 print [[server:uptime() - Show how long the server has been running]]
239 print [[server:memory() - Show details about the server's memory usage]]
239 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] 240 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]]
240 elseif section == "port" then 241 elseif section == "port" then
241 print [[port:list() - Lists all network ports prosody currently listens on]] 242 print [[port:list() - Lists all network ports prosody currently listens on]]
242 print [[port:close(port, interface) - Close a port]] 243 print [[port:close(port, interface) - Close a port]]
243 elseif section == "dns" then 244 elseif section == "dns" then
296 end 297 end
297 298
298 function def_env.server:shutdown(reason) 299 function def_env.server:shutdown(reason)
299 prosody.shutdown(reason); 300 prosody.shutdown(reason);
300 return true, "Shutdown initiated"; 301 return true, "Shutdown initiated";
302 end
303
304 local function human(kb)
305 local unit = "K";
306 if kb > 1024 then
307 kb, unit = kb/1024, "M";
308 end
309 return ("%0.2f%sB"):format(kb, unit);
310 end
311
312 function def_env.server:memory()
313 if not pposix.meminfo then
314 return true, "Lua is using "..collectgarbage("count");
315 end
316 local mem, lua_mem = pposix.meminfo(), collectgarbage("count");
317 local print = self.session.print;
318 print("Process: "..human((mem.allocated+mem.allocated_mmap)/1024));
319 print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)");
320 print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)");
321 return true, "OK";
301 end 322 end
302 323
303 def_env.module = {}; 324 def_env.module = {};
304 325
305 local function get_hosts_set(hosts, module) 326 local function get_hosts_set(hosts, module)