# HG changeset patch # User Matthew Wild # Date 1465820107 -3600 # Node ID 2733cb8c82a9a5831d7a26130da49144e986b1ac # Parent e654d6e1fb5060302ed533c2ab5414ab2b95fcfe mod_statistics: Add 'statistics_meminfo_interval' option to control the number of seconds between calls to mallinfo(). Between calls, cached results are used. diff -r e654d6e1fb50 -r 2733cb8c82a9 mod_statistics/stats.lib.lua --- 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