From 8a2045381830c81b7bf09da835c7a68c864bfac2 Mon Sep 17 00:00:00 2001 From: Gustaw Lippa Date: Thu, 22 Apr 2021 17:28:20 +0200 Subject: [PATCH] Move MAM metrics to mod_mam Now mod_mam is responsible for starting and updating metrics related to MAM. Thanks to this change MAM metrics will not be reported if Mongoose is started with MAM disabled. --- src/mam/mod_mam.erl | 33 +++++++++++++++++--- src/metrics/mongoose_metrics_definitions.hrl | 12 ------- src/metrics/mongoose_metrics_hooks.erl | 3 +- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/mam/mod_mam.erl b/src/mam/mod_mam.erl index 48519c2b446..a5ba51edd64 100644 --- a/src/mam/mod_mam.erl +++ b/src/mam/mod_mam.erl @@ -218,9 +218,7 @@ start(Host, Opts) -> ejabberd_hooks:add(amp_determine_strategy, Host, ?MODULE, determine_amp_strategy, 20), ejabberd_hooks:add(sm_filter_offline_message, Host, ?MODULE, sm_filter_offline_message, 50), ejabberd_hooks:add(get_personal_data, Host, ?MODULE, get_personal_data, 50), - mongoose_metrics:ensure_metric(Host, [backends, ?MODULE, lookup], histogram), - mongoose_metrics:ensure_metric(Host, [Host, modMamLookups, simple], spiral), - mongoose_metrics:ensure_metric(Host, [backends, ?MODULE, archive], histogram), + ensure_metrics(Host), ok. @@ -684,5 +682,32 @@ is_archivable_message(Host, Dir, Packet) -> erlang:apply(M, F, [?MODULE, Dir, Packet, ArchiveChatMarkers]). config_metrics(Host) -> - OptsToReport = [{backend, rdbms}], %list of tuples {option, defualt_value} + OptsToReport = [{backend, rdbms}], %list of tuples {option, default_value} mongoose_module_metrics:opts_for_module(Host, ?MODULE, OptsToReport). + +ensure_metrics(Host) -> + mongoose_metrics:ensure_metric(Host, [backends, ?MODULE, lookup], histogram), + mongoose_metrics:ensure_metric(Host, [Host, modMamLookups, simple], spiral), + mongoose_metrics:ensure_metric(Host, [backends, ?MODULE, archive], histogram), + lists:foreach(fun(Name) -> + mongoose_metrics:ensure_metric(Host, Name, spiral) + end, + spirals()), + lists:foreach(fun(Hook) -> + apply(ejabberd_hooks, add, Hook) + end, + mongoose_metrics_mam_hooks:get_hooks(Host)). + +spirals() -> + [modMamPrefsSets, + modMamPrefsGets, + modMamArchiveRemoved, + modMamLookups, + modMamForwarded, + modMamArchived, + modMamFlushed, + modMamDropped, + modMamDropped2, + modMamDroppedIQ, + modMamSinglePurges, + modMamMultiplePurges]. diff --git a/src/metrics/mongoose_metrics_definitions.hrl b/src/metrics/mongoose_metrics_definitions.hrl index a2ad46335e5..8577b45a4de 100644 --- a/src/metrics/mongoose_metrics_definitions.hrl +++ b/src/metrics/mongoose_metrics_definitions.hrl @@ -35,18 +35,6 @@ modPrivacyStanzaDenied, modPrivacyStanzaBlocked, modPrivacyStanzaAll, - modMamPrefsSets, - modMamPrefsGets, - modMamArchiveRemoved, - modMamLookups, - modMamForwarded, - modMamArchived, - modMamFlushed, - modMamDropped, - modMamDropped2, - modMamDroppedIQ, - modMamSinglePurges, - modMamMultiplePurges, modMucMamPrefsSets, modMucMamPrefsGets, modMucMamArchiveRemoved, diff --git a/src/metrics/mongoose_metrics_hooks.erl b/src/metrics/mongoose_metrics_hooks.erl index 81356ac7aeb..ba1b0a8cad4 100644 --- a/src/metrics/mongoose_metrics_hooks.erl +++ b/src/metrics/mongoose_metrics_hooks.erl @@ -66,8 +66,7 @@ get_hooks(Host) -> {privacy_iq_get, Host, ?MODULE, privacy_iq_get, 1}, {privacy_iq_set, Host, ?MODULE, privacy_iq_set, 1}, {privacy_check_packet, Host, ?MODULE, privacy_check_packet, 55}, - {sm_broadcast, Host, ?MODULE, privacy_list_push, 1} - | mongoose_metrics_mam_hooks:get_hooks(Host)]. + {sm_broadcast, Host, ?MODULE, privacy_list_push, 1}]. -spec sm_register_connection_hook(map(), tuple(), jid:jid(), term() ) -> metrics_notify_return().