Skip to content

Commit 73698ec

Browse files
authored
Support Erlang 23 format for blocks entry in allocators (#102)
1 parent 39ef9d0 commit 73698ec

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/collectors/vm/prometheus_vm_system_info_collector.erl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ collect_allocator_metrics() ->
315315
[
316316
[
317317
allocator_metric(Alloc, Instance, Kind, Key, KindInfo)
318-
|| Key <- [blocks, blocks_size, carriers, carriers_size]]
318+
|| Key <- [carriers, carriers_size]] ++
319+
[
320+
allocator_blocks_metric(Alloc, Instance, Kind, Key, KindInfo)
321+
|| Key <- [count, size]]
322+
319323
|| {Kind, KindInfo} <- Info, (Kind =:= mbcs) orelse (Kind =:= mbcs_pool) orelse (Kind =:= sbcs)]
320324
end || {{Alloc, Instance}, Info} <- allocators()]),
321325
prometheus_model_helpers:gauge_metrics(Metrics).
@@ -334,3 +338,31 @@ allocators() ->
334338
Allocs <- [erlang:system_info({allocator, A})],
335339
Allocs =/= false,
336340
{_, N, Props} <- Allocs].
341+
342+
allocator_blocks_metric(Alloc, Instance, Kind, count, KindInfo) ->
343+
Count = case lists:keyfind(blocks, 1, KindInfo) of
344+
{blocks, L} when is_list(L) ->
345+
sum_alloc_block_list(count, L, 0);
346+
Tuple ->
347+
element(2, Tuple)
348+
end,
349+
{[{alloc, Alloc}, {instance_no, Instance}, {kind, Kind}, {usage, blocks}], Count};
350+
allocator_blocks_metric(Alloc, Instance, Kind, size, KindInfo) ->
351+
Size = case lists:keyfind(blocks_size, 1, KindInfo) of
352+
false ->
353+
sum_alloc_block_list(size, element(2, lists:keyfind(blocks, 1, KindInfo)), 0);
354+
Tuple ->
355+
element(2, Tuple)
356+
end,
357+
{[{alloc, Alloc}, {instance_no, Instance}, {kind, Kind}, {usage, blocks_size}], Size}.
358+
359+
sum_alloc_block_list(Type, [{_, L} | Rest], Acc) ->
360+
Value = case lists:keyfind(Type, 1, L) of
361+
false -> 0;
362+
Tuple -> element(2, Tuple)
363+
end,
364+
sum_alloc_block_list(Type, Rest, Value + Acc);
365+
sum_alloc_block_list(Type, [_ | Rest], Acc) ->
366+
sum_alloc_block_list(Type, Rest, Acc);
367+
sum_alloc_block_list(_Type, [], Acc) ->
368+
Acc.

0 commit comments

Comments
 (0)