Mercurial > prosody-modules
comparison mod_measure_malloc/mod_measure_malloc.lua @ 4575:5b4f43b90766
mod_measure_malloc: port to most recent trunk statistics API
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 25 May 2021 19:01:54 +0200 |
parents | a83eed629d4b |
children | b9af1ccac98b |
comparison
equal
deleted
inserted
replaced
4574:38d80dbfee88 | 4575:5b4f43b90766 |
---|---|
1 module:set_global(); | 1 module:set_global(); |
2 | 2 |
3 local measure = require"core.statsmanager".measure; | 3 local metric = require"core.statsmanager".metric; |
4 local pposix = require"util.pposix"; | 4 local pposix = require"util.pposix"; |
5 | 5 |
6 local measures = {}; | 6 local allocated = metric( |
7 setmetatable(measures, { | 7 "gauge", "malloc_heap_allocated", "bytes", |
8 __index = function (t, k) | 8 "Allocated bytes by mode of allocation", |
9 local m = measure("amount", "memory."..k); t[k] = m; return m; | 9 {"mode"} |
10 ); | |
11 | |
12 local used = metric( | |
13 "gauge", "malloc_heap_used", "bytes", | |
14 "Used bytes" | |
15 ):with_labels(); | |
16 | |
17 local unused = metric( | |
18 "gauge", "malloc_heap_unused", "bytes", | |
19 "Unused bytes" | |
20 ):with_labels(); | |
21 | |
22 local returnable = metric( | |
23 "gauge", "malloc_heap_returnable", "bytes", | |
24 "Returnable bytes" | |
25 ):with_labels(); | |
26 | |
27 module:hook("stats-update", function () | |
28 meminfo = pposix.meminfo(); | |
29 if meminfo.allocated then | |
30 allocated:with_labels("sbrk"):set(meminfo.allocated); | |
10 end | 31 end |
11 }); | 32 if meminfo.allocated_mmap then |
12 module:hook("stats-update", function () | 33 allocated:with_labels("mmap"):set(meminfo.allocated_mmap); |
13 local m = measures; | 34 end |
14 for k, v in pairs(pposix.meminfo()) do | 35 if meminfo.used then |
15 m[k](v); | 36 used:set(meminfo.used); |
37 end | |
38 if meminfo.unused then | |
39 unused:set(meminfo.unused); | |
40 end | |
41 if meminfo.returnable then | |
42 returnable:set(meminfo.returnable); | |
16 end | 43 end |
17 end); | 44 end); |