annotate mod_measure_memory/mod_measure_memory.lua @ 3955:017f60608fc8

mod_smacks: also count outgoing MAM messages mod_smacks doesn't count outgoing MAM messages, which causes warnings in Prosody such as: > The client says it handled 41 new stanzas, but we only sent 2 It seems mod_smacks is in the wrong here and that it's too strict in trying to determine what is a valid stanza to count. In RFC6120: > Definition of XML Stanza: An XML stanza is the basic unit of meaning > in XMPP. A stanza is a first-level element (at depth=1 of the stream) > whose element name is "message", "presence", or "iq" and whose > qualifying namespace is 'jabber:client' or 'jabber:server'.
author JC Brand <jc@opkode.com>
date Thu, 26 Mar 2020 11:57:02 +0100
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