Skip to content

Commit ffe2bf7

Browse files
author
Loïc Hoguin
authored
Handle case where mnesia:table_info/2 returns undefined (#140)
1 parent 06425c2 commit ffe2bf7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/collectors/mnesia/prometheus_mnesia_collector.erl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,31 @@ metric_enabled(Name, Metrics) ->
196196
get_memory_usage() ->
197197
WordSize = erlang:system_info(wordsize),
198198
Calculator = fun(Tab, Sum) ->
199-
mnesia:table_info(Tab, memory) + Sum
199+
table_info(Tab, memory) + Sum
200200
end,
201201
lists:foldl(Calculator, 0, mnesia:system_info(tables)) * WordSize.
202202

203203
get_tablewise_memory_usage() ->
204204
WordSize = erlang:system_info(wordsize),
205205
Calculator =
206206
fun(Tab, Acc) ->
207-
[{[{table, Tab}], mnesia:table_info(Tab, memory) * WordSize} | Acc]
207+
[{[{table, Tab}], table_info(Tab, memory) * WordSize} | Acc]
208208
end,
209209
lists:foldl(Calculator, [], mnesia:system_info(tables)).
210210

211211
get_tablewise_size() ->
212212
Calculator =
213213
fun(Tab, Acc) ->
214-
[{[{table, Tab}], mnesia:table_info(Tab, size)} | Acc]
214+
[{[{table, Tab}], table_info(Tab, size)} | Acc]
215215
end,
216216
lists:foldl(Calculator, [], mnesia:system_info(tables)).
217+
218+
%% mnesia:table_info/2 may return 'undefined' when the table should
219+
%% be loaded on the local node but hasn't been loaded yet.
220+
%%
221+
%% https://github.com/erlang/otp/issues/5830
222+
table_info(Tab, Item) ->
223+
case mnesia:table_info(Tab, Item) of
224+
undefined -> 0;
225+
Val -> Val
226+
end.

0 commit comments

Comments
 (0)