diff mod_measure_lua/mod_measure_lua.lua @ 4578:d95fcde6e39d

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.
author Jonas Schäfer <jonas@wielicki.name>
date Sat, 29 May 2021 12:12:17 +0200
parents
children 3c3f45241317
line wrap: on
line diff
--- /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);
+