Packages
prometheus
4.2.2
6.1.3
6.1.2
6.1.1
6.1.0
6.0.3
6.0.2
6.0.1
6.0.0
5.1.1
5.1.0
5.0.0
4.13.0
retired
4.12.0
4.11.0
4.10.0
4.9.1
4.9.0
4.8.2
4.8.1
4.8.0
4.6.0
4.5.0
4.4.1
4.4.0
4.3.0
4.2.2
4.2.0
4.1.0
4.0.1
4.0.0
3.5.1
3.5.0
3.4.6
3.4.5
3.4.4
3.4.3
3.4.2
3.4.1
3.4.0
3.3.2
3.3.1
3.3.0
3.2.3
3.2.2
3.2.1
3.1.1
3.1.0
3.0.1
3.0.0
3.0.0-rc1
3.0.0-alpha9
3.0.0-alpha8
3.0.0-alpha7
3.0.0-alpha6
3.0.0-alpha5
3.0.0-alpha4
3.0.0-alpha3
3.0.0-alpha2
3.0.0-alpha10
3.0.0-alpha1
2.2.0
2.1.0
2.0.0
1.7.0
1.6.0
1.5.0
1.0.2
1.0.1
1.0.0
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
Prometheus.io client in Erlang
Current section
Files
Jump to
Current section
Files
src/contrib/prometheus_mnesia.erl
%% @doc
%% Mnesia instrumentation helpers.
%% @end
-module(prometheus_mnesia).
-export([table_disk_size/1,
table_disk_size/2,
tm_info/0]).
%%====================================================================
%% Macros
%%====================================================================
-define(EXTS, [".DAT", ".TMP", ".DMP", ".DCD", ".DCL", ".LOGTMP"]).
%%====================================================================
%% Public API
%%====================================================================
%% @equiv table_disk_size(mnesia:system_info(directory), Table)
-spec table_disk_size( Table) -> Size when
Table :: file:name_all(),
Size :: non_neg_integer().
table_disk_size(Table) ->
table_disk_size(mnesia:system_info(directory), Table).
%% @doc
%% Returns sum of all mnesia files for the given `Table' in bytes.
%% Mnesia can create different files for each table:
%% - .DAT - DETS files
%% - .TMP - temp files
%% - .DMP - dumped ets tables
%% - .DCD - disc copies data
%% - .DCL - disc copies log
%% - .LOGTMP - disc copies log
%%
%% More on Mnesia files can be found in
%% <a href="http://erlang.org/doc/apps/mnesia/Mnesia_chap7.html">
%% Mnesia System Information chapter
%% </a> of Mnesia User's Guide
%% @end
-spec table_disk_size(Dir, Table) -> Size when
Dir :: file:name_all(),
Table :: file:name_all(),
Size :: non_neg_integer().
table_disk_size(Dir, Table) ->
lists:sum(lists:map(fun(Ext) ->
filelib:file_size(table_path(Dir, Table, Ext))
end,
?EXTS)).
%% @doc
%% Returns {PCount, CCount} tuple, where
%% PCount is a number of participant transactions and
%% CCount is a number of coordinator transactions.
%% Can return {undefined, undefined} occasionally.
%% @end
-spec tm_info() -> {Ps, Cs} | {undefined, undefined} when
Ps :: non_neg_integer(),
Cs :: non_neg_integer().
tm_info() ->
case mnesia_tm:get_info(1000) of
{info, Ps, Cs} -> {length(Ps), length(Cs)};
_ -> {undefined, undefined}
end.
%%====================================================================
%% Private Parts
%%====================================================================
table_path(Dir, Table, Ext) ->
filename:join(Dir, [Table, Ext]).