Comparison

mod_statistics/stats.lib.lua @ 1081:3e2c4f424797

mod_statistics: Remove expensive and non-portable /proc-based memory stats
author Matthew Wild <mwild1@gmail.com>
date Sat, 15 Jun 2013 22:07:35 +0100
parent 1080:3af947e2e6d4
child 2209:2733cb8c82a9
comparison
equal deleted inserted replaced
1080:3af947e2e6d4 1081:3e2c4f424797
106 get = function () return math.ceil(pposix.meminfo().returnable); end; 106 get = function () return math.ceil(pposix.meminfo().returnable); end;
107 tostring = human; 107 tostring = human;
108 } 108 }
109 end 109 end
110 110
111 local pagesize = 4096;
112 stats.memory_total = {
113 get = function ()
114 local statm, err = io.open"/proc/self/statm";
115 if statm then
116 local total = statm:read"*n";
117 statm:close();
118 return total * pagesize;
119 else
120 module:log("debug", err);
121 end
122 end;
123 tostring = human;
124 };
125 stats.memory_rss = {
126 get = function ()
127 local statm, err = io.open"/proc/self/statm";
128 if statm then
129 statm:read"*n"; -- Total size, ignore
130 local rss = statm:read"*n";
131 statm:close();
132 return rss * pagesize;
133 else
134 module:log("debug", err);
135 end
136 end;
137 tostring = human;
138 };
139
140 local add_statistics_filter; -- forward decl 111 local add_statistics_filter; -- forward decl
141 if prosody and prosody.arg then -- ensures we aren't in prosodyctl 112 if prosody and prosody.arg then -- ensures we aren't in prosodyctl
142 setmetatable(active_sessions, { 113 setmetatable(active_sessions, {
143 __index = function ( t, k ) 114 __index = function ( t, k )
144 local v = { 115 local v = {