annotate mod_measure_memory/mod_measure_memory.lua @ 3656:3e0f4d727825

mod_vcard_muc: Add an alternative method of signaling avatar change When the avatar has been changed, a signal is sent that the room configuration has changed. Clients then do a disco#info query to find the SHA-1 of the new avatar. They can then fetch it as before, or not if they have it cached already. This is meant to be less disruptive than signaling via presence, which caused problems for some clients. If clients transition to the new method, the old one can eventually be removed. The namespace is made up while waiting for standardization. Otherwise it is very close to what's described in https://xmpp.org/extensions/inbox/muc-avatars.html
author Kim Alvefur <zash@zash.se>
date Sun, 25 Aug 2019 20:46:43 +0200
parents a5a5f85d7ca1
children e17c937a71b3
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)
3365
a5a5f85d7ca1 mod_measure_memory: Use the 'amount' measure type
Kim Alvefur <zash@zash.se>
parents: 2708
diff changeset
8 local m = measure("amount", "memory."..k); 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