From 8485ebb62595d440c3c2172206c8c7b1f5c5b803 Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Fri, 28 Jul 2023 15:34:06 +0200 Subject: [PATCH] Reorder app startup First config, then metrics, then everything else, including dependent metrics at the end --- src/ejabberd_app.erl | 5 +- src/metrics/mongoose_metrics.erl | 51 +++++++++++++------- src/metrics/mongoose_metrics_definitions.hrl | 10 ++-- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl index a5d6b4cb17a..df8d6fcb0c9 100644 --- a/src/ejabberd_app.erl +++ b/src/ejabberd_app.erl @@ -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), @@ -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(), @@ -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; diff --git a/src/metrics/mongoose_metrics.erl b/src/metrics/mongoose_metrics.erl index 4c4eb7ae431..7665bdd8166 100644 --- a/src/metrics/mongoose_metrics.erl +++ b/src/metrics/mongoose_metrics.erl @@ -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, @@ -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(), @@ -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); diff --git a/src/metrics/mongoose_metrics_definitions.hrl b/src/metrics/mongoose_metrics_definitions.hrl index 0b1cfc199b4..7bb317252fa 100644 --- a/src/metrics/mongoose_metrics_definitions.hrl +++ b/src/metrics/mongoose_metrics_definitions.hrl @@ -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],