Skip to content

Commit

Permalink
Support Erlang 23 format for blocks entry in allocators (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcorbacho authored Feb 3, 2020
1 parent 39ef9d0 commit 73698ec
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/collectors/vm/prometheus_vm_system_info_collector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ collect_allocator_metrics() ->
[
[
allocator_metric(Alloc, Instance, Kind, Key, KindInfo)
|| Key <- [blocks, blocks_size, carriers, carriers_size]]
|| Key <- [carriers, carriers_size]] ++
[
allocator_blocks_metric(Alloc, Instance, Kind, Key, KindInfo)
|| Key <- [count, size]]

|| {Kind, KindInfo} <- Info, (Kind =:= mbcs) orelse (Kind =:= mbcs_pool) orelse (Kind =:= sbcs)]
end || {{Alloc, Instance}, Info} <- allocators()]),
prometheus_model_helpers:gauge_metrics(Metrics).
Expand All @@ -334,3 +338,31 @@ allocators() ->
Allocs <- [erlang:system_info({allocator, A})],
Allocs =/= false,
{_, N, Props} <- Allocs].

allocator_blocks_metric(Alloc, Instance, Kind, count, KindInfo) ->
Count = case lists:keyfind(blocks, 1, KindInfo) of
{blocks, L} when is_list(L) ->
sum_alloc_block_list(count, L, 0);
Tuple ->
element(2, Tuple)
end,
{[{alloc, Alloc}, {instance_no, Instance}, {kind, Kind}, {usage, blocks}], Count};
allocator_blocks_metric(Alloc, Instance, Kind, size, KindInfo) ->
Size = case lists:keyfind(blocks_size, 1, KindInfo) of
false ->
sum_alloc_block_list(size, element(2, lists:keyfind(blocks, 1, KindInfo)), 0);
Tuple ->
element(2, Tuple)
end,
{[{alloc, Alloc}, {instance_no, Instance}, {kind, Kind}, {usage, blocks_size}], Size}.

sum_alloc_block_list(Type, [{_, L} | Rest], Acc) ->
Value = case lists:keyfind(Type, 1, L) of
false -> 0;
Tuple -> element(2, Tuple)
end,
sum_alloc_block_list(Type, Rest, Value + Acc);
sum_alloc_block_list(Type, [_ | Rest], Acc) ->
sum_alloc_block_list(Type, Rest, Acc);
sum_alloc_block_list(_Type, [], Acc) ->
Acc.

0 comments on commit 73698ec

Please sign in to comment.