Mercurial > prosody-modules
annotate mod_measure_memory/mod_measure_memory.lua @ 4542:fb4a50bf60f1
mod_prometheus: Invoke stats collection if in 'manual' mode
Since 10d13e0554f9 a special value for statistics_interval "manual"
exists, where a module is expected to invoke processing in connection to
collection of stats. This makes internal collection and exporting to
Prometheus happens at the same time with no chance of timers getting out
of sync.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 13 Apr 2021 23:53:53 +0200 |
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 |