Software /
code /
prosody-modules
Comparison
mod_statistics/stats.lib.lua @ 2209:2733cb8c82a9
mod_statistics: Add 'statistics_meminfo_interval' option to control the number of seconds between calls to mallinfo(). Between calls, cached results are used.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 13 Jun 2016 13:15:07 +0100 |
parent | 1081:3e2c4f424797 |
child | 2300:dded110af017 |
comparison
equal
deleted
inserted
replaced
2208:e654d6e1fb50 | 2209:2733cb8c82a9 |
---|---|
29 local active_sessions, active_jids = {}, {}; | 29 local active_sessions, active_jids = {}, {}; |
30 local c2s_sessions, s2s_sessions; | 30 local c2s_sessions, s2s_sessions; |
31 if prosody and prosody.arg then | 31 if prosody and prosody.arg then |
32 c2s_sessions, s2s_sessions = module:shared("/*/c2s/sessions", "/*/s2s/sessions"); | 32 c2s_sessions, s2s_sessions = module:shared("/*/c2s/sessions", "/*/s2s/sessions"); |
33 end | 33 end |
34 | |
35 local memory_update_interval = module:get_option_number("statistics_meminfo_interval", 60); | |
34 | 36 |
35 local stats = { | 37 local stats = { |
36 total_users = { | 38 total_users = { |
37 get = function () return it.count(it.keys(bare_sessions)); end | 39 get = function () return it.count(it.keys(bare_sessions)); end |
38 }; | 40 }; |
88 tostring = "%s%%"; | 90 tostring = "%s%%"; |
89 }; | 91 }; |
90 }; | 92 }; |
91 | 93 |
92 if has_pposix and pposix.meminfo then | 94 if has_pposix and pposix.meminfo then |
95 | |
96 local cached_meminfo, last_cache_update; | |
97 local function meminfo() | |
98 if not cached_meminfo or (os.time() - last_cache_update) > memory_update_interval then | |
99 cached_meminfo = pposix.meminfo(); | |
100 last_cache_update = os.time(); | |
101 end | |
102 return cached_meminfo; | |
103 end | |
104 | |
93 stats.memory_allocated = { | 105 stats.memory_allocated = { |
94 get = function () return math.ceil(pposix.meminfo().allocated); end; | 106 get = function () return math.ceil(meminfo().allocated); end; |
95 tostring = human; | 107 tostring = human; |
96 } | 108 } |
97 stats.memory_used = { | 109 stats.memory_used = { |
98 get = function () return math.ceil(pposix.meminfo().used); end; | 110 get = function () return math.ceil(meminfo().used); end; |
99 tostring = human; | 111 tostring = human; |
100 } | 112 } |
101 stats.memory_unused = { | 113 stats.memory_unused = { |
102 get = function () return math.ceil(pposix.meminfo().unused); end; | 114 get = function () return math.ceil(meminfo().unused); end; |
103 tostring = human; | 115 tostring = human; |
104 } | 116 } |
105 stats.memory_returnable = { | 117 stats.memory_returnable = { |
106 get = function () return math.ceil(pposix.meminfo().returnable); end; | 118 get = function () return math.ceil(meminfo().returnable); end; |
107 tostring = human; | 119 tostring = human; |
108 } | 120 } |
109 end | 121 end |
110 | 122 |
111 local add_statistics_filter; -- forward decl | 123 local add_statistics_filter; -- forward decl |