Mercurial > prosody-modules
annotate mod_measure_memory/mod_measure_memory.lua @ 4210:a0937b5cfdcb
mod_invites_page: Remove preauth URI button
This button is incompatible with the majority of XMPP clients around, yet based
on feedback from users, many are drawn to click it when they have any XMPP client
installed already.
In the case where the user already has software installed, we would prefer them to
select it from the software list so they can follow the setup process suited to
their specific client (we already track which software supports preauth URIs). If
their client is not listed, they can still use the manual registration link instead.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 16 Oct 2020 11:03:38 +0100 |
parents | e17c937a71b3 |
children |
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 |