feat: upsert stats counters, daily buckets and ETS tops for admin metrics. Refs EventHub/EventHubBack#42 #43 #44 #45 #46
This commit is contained in:
@@ -72,8 +72,27 @@ stop_mnesia() ->
|
||||
|
||||
ensure_tables(Tables) when is_list(Tables) ->
|
||||
lists:foreach(fun ensure_table/1, Tables),
|
||||
maybe_add_admin_stats_indexes(Tables),
|
||||
ok.
|
||||
|
||||
maybe_add_admin_stats_indexes(Tables) ->
|
||||
case lists:member(report, Tables) of
|
||||
true -> add_index(report, resolved_by);
|
||||
false -> ok
|
||||
end,
|
||||
case lists:member(ticket, Tables) of
|
||||
true -> add_index(ticket, assigned_to);
|
||||
false -> ok
|
||||
end.
|
||||
|
||||
add_index(Table, Attr) ->
|
||||
case catch mnesia:add_table_index(Table, Attr) of
|
||||
{atomic, ok} -> ok;
|
||||
{aborted, {already_exists, _}} -> ok;
|
||||
{aborted, {already_exists, _, _}} -> ok;
|
||||
_ -> ok
|
||||
end.
|
||||
|
||||
ensure_table(Table) ->
|
||||
case lists:member(Table, mnesia:system_info(tables)) of
|
||||
true ->
|
||||
@@ -133,8 +152,10 @@ table_opts(admin_audit) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, admin_audit)}];
|
||||
table_opts(notification) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, notification)}];
|
||||
table_opts(stats) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, stats)}];
|
||||
table_opts(stats_counter) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, stats_counter)}];
|
||||
table_opts(stats_daily) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, stats_daily)}];
|
||||
table_opts(session) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, session)}];
|
||||
table_opts(verification) ->
|
||||
|
||||
Reference in New Issue
Block a user