Software /
code /
prosody-modules
Changeset
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 |
parents | 2208:e654d6e1fb50 |
children | 2211:9aecf7c953ba |
files | mod_statistics/stats.lib.lua |
diffstat | 1 files changed, 16 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_statistics/stats.lib.lua Sun Jun 12 03:21:48 2016 +0200 +++ b/mod_statistics/stats.lib.lua Mon Jun 13 13:15:07 2016 +0100 @@ -32,6 +32,8 @@ c2s_sessions, s2s_sessions = module:shared("/*/c2s/sessions", "/*/s2s/sessions"); end +local memory_update_interval = module:get_option_number("statistics_meminfo_interval", 60); + local stats = { total_users = { get = function () return it.count(it.keys(bare_sessions)); end @@ -90,20 +92,30 @@ }; if has_pposix and pposix.meminfo then + + local cached_meminfo, last_cache_update; + local function meminfo() + if not cached_meminfo or (os.time() - last_cache_update) > memory_update_interval then + cached_meminfo = pposix.meminfo(); + last_cache_update = os.time(); + end + return cached_meminfo; + end + stats.memory_allocated = { - get = function () return math.ceil(pposix.meminfo().allocated); end; + get = function () return math.ceil(meminfo().allocated); end; tostring = human; } stats.memory_used = { - get = function () return math.ceil(pposix.meminfo().used); end; + get = function () return math.ceil(meminfo().used); end; tostring = human; } stats.memory_unused = { - get = function () return math.ceil(pposix.meminfo().unused); end; + get = function () return math.ceil(meminfo().unused); end; tostring = human; } stats.memory_returnable = { - get = function () return math.ceil(pposix.meminfo().returnable); end; + get = function () return math.ceil(meminfo().returnable); end; tostring = human; } end