# HG changeset patch # User Jonas Schäfer # Date 1621962114 -7200 # Node ID 5b4f43b90766c8c428a55b1983a2fb3e8595076b # Parent 38d80dbfee883c894695168334d9a87c496f325b mod_measure_malloc: port to most recent trunk statistics API diff -r 38d80dbfee88 -r 5b4f43b90766 mod_measure_malloc/README.markdown --- a/mod_measure_malloc/README.markdown Tue May 25 16:49:51 2021 +0200 +++ b/mod_measure_malloc/README.markdown Tue May 25 19:01:54 2021 +0200 @@ -7,5 +7,5 @@ Description =========== -This module collects stats from `util.pposix.meminfo` usage and reports using Prosody 0.10 APIs +This module collects stats from `util.pposix.meminfo` usage and reports using Prosody 0.12 APIs diff -r 38d80dbfee88 -r 5b4f43b90766 mod_measure_malloc/mod_measure_malloc.lua --- a/mod_measure_malloc/mod_measure_malloc.lua Tue May 25 16:49:51 2021 +0200 +++ b/mod_measure_malloc/mod_measure_malloc.lua Tue May 25 19:01:54 2021 +0200 @@ -1,17 +1,44 @@ module:set_global(); -local measure = require"core.statsmanager".measure; +local metric = require"core.statsmanager".metric; local pposix = require"util.pposix"; -local measures = {}; -setmetatable(measures, { - __index = function (t, k) - local m = measure("amount", "memory."..k); t[k] = m; return m; +local allocated = metric( + "gauge", "malloc_heap_allocated", "bytes", + "Allocated bytes by mode of allocation", + {"mode"} +); + +local used = metric( + "gauge", "malloc_heap_used", "bytes", + "Used bytes" +):with_labels(); + +local unused = metric( + "gauge", "malloc_heap_unused", "bytes", + "Unused bytes" +):with_labels(); + +local returnable = metric( + "gauge", "malloc_heap_returnable", "bytes", + "Returnable bytes" +):with_labels(); + +module:hook("stats-update", function () + meminfo = pposix.meminfo(); + if meminfo.allocated then + allocated:with_labels("sbrk"):set(meminfo.allocated); end -}); -module:hook("stats-update", function () - local m = measures; - for k, v in pairs(pposix.meminfo()) do - m[k](v); + if meminfo.allocated_mmap then + allocated:with_labels("mmap"):set(meminfo.allocated_mmap); + end + if meminfo.used then + used:set(meminfo.used); + end + if meminfo.unused then + unused:set(meminfo.unused); + end + if meminfo.returnable then + returnable:set(meminfo.returnable); end end);