Skip to content

Commit

Permalink
Reorder app startup
Browse files Browse the repository at this point in the history
First config, then metrics, then everything else, including dependent metrics at the end
  • Loading branch information
NelsonVides committed Jul 31, 2023
1 parent e778de6 commit 8485ebb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ start(normal, _Args) ->
mongoose_fips:notify(),
write_pid_file(),
update_status_file(starting),
mongoose_config:start(),
mongoose_metrics:init(),
db_init(),
application:start(cache_tab),

Expand All @@ -51,7 +53,6 @@ start(normal, _Args) ->
ejabberd_node_id:start(),
ejabberd_commands:init(),
mongoose_graphql_commands:start(),
mongoose_config:start(),
mongoose_router:start(),
mongoose_logs:set_global_loglevel(mongoose_config:get_opt(loglevel)),
mongoose_deprecations:start(),
Expand All @@ -67,9 +68,9 @@ start(normal, _Args) ->
mongoose_service:start(),
mongoose_modules:start(),
service_mongoose_system_metrics:verify_if_configured(),
mongoose_metrics:init(),
mongoose_listener:start(),
ejabberd_admin:start(),
mongoose_metrics:init_mongooseim_metrics(),
update_status_file(started),
?LOG_NOTICE(#{what => mongooseim_node_started, version => ?MONGOOSE_VERSION, node => node()}),
Sup;
Expand Down
51 changes: 33 additions & 18 deletions src/metrics/mongoose_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

%% API
-export([init/0,
init_mongooseim_metrics/0,
create_generic_hook_metric/2,
create_probe_metric/3,
ensure_db_pool_metric/1,
Expand Down Expand Up @@ -65,24 +66,16 @@
-spec init() -> ok.
init() ->
prepare_prefixes(),
create_global_metrics(),
lists:foreach(fun init_predefined_host_type_metrics/1, ?ALL_HOST_TYPES),
create_vm_metrics(),
create_global_metrics(?GLOBAL_COUNTERS),
create_data_metrics(),
create_host_type_metrics(),
init_subscriptions().

create_global_metrics() ->
lists:foreach(fun({Metric, FunSpec, DataPoints}) ->
FunSpecTuple = list_to_tuple(FunSpec ++ [DataPoints]),
catch ensure_metric(global, Metric, FunSpecTuple)
end, ?VM_STATS),
lists:foreach(fun({Metric, Spec}) -> ensure_metric(global, Metric, Spec) end,
?GLOBAL_COUNTERS),
create_data_metrics().

-spec init_predefined_host_type_metrics(mongooseim:host_type()) -> ok.
init_predefined_host_type_metrics(HostType) ->
create_metrics(HostType),
Hooks = mongoose_metrics_hooks:get_hooks(HostType),
gen_hook:add_handlers(Hooks).
-spec init_mongooseim_metrics() -> ok.
init_mongooseim_metrics() ->
create_host_type_hook_metrics(),
create_global_metrics(?MNESIA_COUNTERS).

init_subscriptions() ->
Reporters = exometer_report:list_reporters(),
Expand Down Expand Up @@ -397,12 +390,34 @@ filter_hook(mam_muc_flush_messages) -> skip;

filter_hook(_) -> use.

-spec create_metrics(mongooseim:host_type()) -> 'ok'.
create_metrics(HostType) ->
create_global_metrics(Metrics) ->
lists:foreach(fun({Metric, Spec}) -> ensure_metric(global, Metric, Spec) end, Metrics).

create_vm_metrics() ->
lists:foreach(fun({Metric, FunSpec, DataPoints}) ->
FunSpecTuple = list_to_tuple(FunSpec ++ [DataPoints]),
catch ensure_metric(global, Metric, FunSpecTuple)
end, ?VM_STATS).

-spec create_host_type_metrics() -> ok.
create_host_type_metrics() ->
lists:foreach(fun create_host_type_metrics/1, ?ALL_HOST_TYPES).

-spec create_host_type_metrics(mongooseim:host_type()) -> 'ok'.
create_host_type_metrics(HostType) ->
lists:foreach(fun(Name) -> ensure_metric(HostType, Name, spiral) end, ?GENERAL_SPIRALS),
lists:foreach(fun(Name) -> ensure_metric(HostType, Name, histogram) end, ?GENERAL_HISTOGRAMS),
lists:foreach(fun(Name) -> ensure_metric(HostType, Name, counter) end, ?TOTAL_COUNTERS).

-spec create_host_type_hook_metrics() -> ok.
create_host_type_hook_metrics() ->
lists:foreach(fun create_host_type_hook_metrics/1, ?ALL_HOST_TYPES).

-spec create_host_type_hook_metrics(mongooseim:host_type()) -> 'ok'.
create_host_type_hook_metrics(HostType) ->
Hooks = mongoose_metrics_hooks:get_hooks(HostType),
gen_hook:add_handlers(Hooks).

ensure_metric(HostType, Metric, Type, ShortType) when is_atom(Metric) ->
ensure_metric(HostType, [Metric], Type, ShortType);

Expand Down
10 changes: 7 additions & 3 deletions src/metrics/mongoose_metrics_definitions.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@
[{nodeUpTime,
{function, mongoose_metrics, get_up_time, [],
tagged, [value]}},
{clusterSize,
{function, mongoose_metrics, get_mnesia_running_db_nodes_count, [],
tagged, [value]}},
?PROBE(tcpPortsUsed, mongoose_metrics_probe_tcp),
?PROBE(processQueueLengths, mongoose_metrics_probe_queues)
]
).

-define(MNESIA_COUNTERS,
[{clusterSize,
{function, mongoose_metrics, get_mnesia_running_db_nodes_count, [],
tagged, [value]}}
]
).

-define(VM_STATS, [{[erlang, system_info], [function, erlang, system_info, ['$dp'], value],
[port_count, port_limit, process_count, process_limit, ets_limit]},
{[erlang, memory], [function, erlang, memory, ['$dp'], value],
Expand Down

0 comments on commit 8485ebb

Please sign in to comment.