annotate mod_measure_memory/mod_measure_memory.lua @ 4738:5aee8d86629a

mod_bookmarks2: Fix handling of nick and password elements This form of child retrieval fails when the stanza elements internally don't have an 'xmlns' attribute, which can happen sometimes for some reason, including when they have been constructed via the stanza builder API. When that is the case then the explicit namespace arguemnt does not match the nil value of the internal attribute. Calling `:get_child()` without the namespace argument does the right thing here, with both nil and the parent namespace as valid values for the internal attribute.
author Kim Alvefur <zash@zash.se>
date Wed, 03 Nov 2021 21:11:55 +0100
parents e17c937a71b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1623
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 module:set_global();
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local measure = require"core.statsmanager".measure;
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local measures = {};
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 setmetatable(measures, {
1655
4d38b8c03dfe mod_measure_memory: Silence warnings [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1623
diff changeset
7 __index = function (t, k)
4040
e17c937a71b3 mod_measure_memory: Report that stats are in units of bytes
Kim Alvefur <zash@zash.se>
parents: 3365
diff changeset
8 local m = measure("amount", "memory."..k, { units = "bytes" }); t[k] = m; return m;
1623
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 end
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 });
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 module:hook("stats-update", function ()
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 measures.lua(collectgarbage("count")*1024);
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 end);
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
1655
4d38b8c03dfe mod_measure_memory: Silence warnings [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1623
diff changeset
16 if require"lfs".attributes("/proc/self/statm", "mode") == "file" then
1623
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local pagesize = module:get_option_number("memory_pagesize", 4096); -- getconf PAGESIZE
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 module:hook("stats-update", function ()
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local statm, err = io.open("/proc/self/statm");
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 if not statm then
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 module:log("error", tostring(err));
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 return;
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 -- virtual memory (caches, opened librarys, everything)
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 measures.total(statm:read("*n") * pagesize);
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 -- resident set size (actually used memory)
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 measures.rss(statm:read("*n") * pagesize);
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 statm:close();
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end);
2c39af0fb93b mod_measure_memory: Module for polling memory useage from Lua, meminfo() and /proc depending on availability
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end