annotate mod_measure_memory/mod_measure_memory.lua @ 1652:9a3d2f1479a4

mod_s2s_auth_dane: Cleanup [luacheck]
author Kim Alvefur <zash@zash.se>
date Tue, 07 Apr 2015 17:35:20 +0200
parents 2c39af0fb93b
children 4d38b8c03dfe
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 local have_pposix, pposix = pcall(require, "util.pposix");
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
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 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
7 setmetatable(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
8 __index = function (t, k, m)
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 m = measure("sizes", "memory."..k); t[k] = m; return m;
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 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
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
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 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
14 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
15 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
16
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 if have_pposix and pposix.meminfo 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
18 module:hook_global("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
19 local m = 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
20 for k, v in pairs(pposix.meminfo()) do
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 m[k](v);
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 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
23 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
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
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 local statm = 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
27 if 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
28 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
29 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
30
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 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
32 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
33 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
34 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
35 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
36 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
37 -- 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
38 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
39 -- 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
40 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
41 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
42 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
43 end