# HG changeset patch # User Jonas Schäfer # Date 1622283137 -7200 # Node ID d95fcde6e39d6aea7ceb54289823a792a6c0b328 # Parent 253df0798996e936d463fcdcd11e49dab3bf9a4b mod_measure_lua: add openmetrics-spirited way to collect lua memory use In the spirit of separate collectors found in other Prometheus packages, this is a separate module to collect metrics related to the lua stack itself. diff -r 253df0798996 -r d95fcde6e39d mod_measure_lua/mod_measure_lua.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_measure_lua/mod_measure_lua.lua Sat May 29 12:12:17 2021 +0200 @@ -0,0 +1,13 @@ +module:set_global() + +local custom_metric = require "core.statsmanager".metric +local gc_bytes = custom_metric( + "gauge", "lua_heap", "bytes", + "Memory used by objects under control of the Lua garbage collector" +):with_labels() + +module:hook("stats-update", function () + local kbytes = collectgarbage("count"); + gc_bytes:set(kbytes * 1024); +end); +