Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement running and total mnesia node count metrics #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/collectors/mnesia/prometheus_mnesia_collector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ metrics(EnabledMetrics) ->
MemoryUsage = get_memory_usage(),
TablewiseMemoryUsage = get_tablewise_memory_usage(),
TablewiseSize = get_tablewise_size(),

Nodes = mnesia:system_info(db_nodes),
Running = mnesia:system_info(running_db_nodes),
[{held_locks, gauge,
"Number of held locks.",
fun() -> ets:info(mnesia_held_locks, size) end},
Expand Down Expand Up @@ -157,7 +158,17 @@ metrics(EnabledMetrics) ->
fun() -> TablewiseMemoryUsage end},
{tablewise_size, gauge,
"Number of rows present per table",
fun() -> TablewiseSize end}
fun() -> TablewiseSize end},
{known_node_count, gauge,
"Count of known mnesia nodes",
fun() -> length(Nodes) end},
{running_node_count, gauge,
"Count of running mnesia nodes",
fun() -> length(Running) end},
{node_state,
gauge, "Mnesia connection state."
"The state is represented as a numerical value where not_connected = 0, connected = 1",
fun() -> get_node_state_metrics(Nodes, Running) end}
].

%%====================================================================
Expand Down Expand Up @@ -214,3 +225,15 @@ get_tablewise_size() ->
[{[{table, Tab}], mnesia:table_info(Tab, size)} | Acc]
end,
lists:foldl(Calculator, [], mnesia:system_info(tables)).

get_node_state_metrics(Nodes, Running) ->
LocalNode = node(),
lists:filtermap(fun(Node) ->
Labels = [{peer, Node}],
case lists:member(Node, Running) of
_ when LocalNode =:= Node -> false;
true ->
{true, {Labels, 1}};
false -> {true, {Labels, 0}}
end
end, Nodes).
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ test_mnesia_on_collector_env_off() ->
?assertMatch(nomatch, re:run(Metrics, "erlang_mnesia_logged_transactions")),
?assertMatch(nomatch, re:run(Metrics, "erlang_mnesia_restarted_transactions")),
?assertMatch(nomatch, re:run(Metrics, "erlang_mnesia_memory_usage_bytes")),
?assertMatch(nomatch, re:run(Metrics, "erlang_mnesia_total_node_count")),
?assertMatch(nomatch, re:run(Metrics, "erlang_mnesia_running_node_count")),
?assertMatch(nomatch, re:run(Metrics, "erlang_mnesia_node_state")),
application:unset_env(prometheus,mnesia_collector_metrics,[]).

test_mnesia_on_collector() ->
Expand All @@ -66,7 +69,12 @@ test_mnesia_on_collector() ->
?assertMatch({match,_}, re:run(Metrics, "erlang_mnesia_committed_transactions")),
?assertMatch({match,_}, re:run(Metrics, "erlang_mnesia_logged_transactions")),
?assertMatch({match,_}, re:run(Metrics, "erlang_mnesia_restarted_transactions")),
?assertMatch({match,_}, re:run(Metrics, "erlang_mnesia_memory_usage_bytes")).
?assertMatch({match,_}, re:run(Metrics, "erlang_mnesia_memory_usage_bytes")),
?assertMatch({match,_}, re:run(Metrics, "erlang_mnesia_known_node_count 1")),
?assertMatch({match,_}, re:run(Metrics, "erlang_mnesia_running_node_count 1")),
% we dont have any node state in case of a single node cluster
?assertMatch(nomatch, re:run(Metrics, "erlang_mnesia_node_state")).


test_mnesia_on_collector_global_labels() ->
Metrics = try
Expand Down