Skip to content

Commit

Permalink
Move MAM metrics to mod_mam
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gustawlippa committed Apr 23, 2021
1 parent 590150f commit 0a340f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
31 changes: 27 additions & 4 deletions src/mam/mod_mam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down Expand Up @@ -684,5 +682,30 @@ 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()),
Hooks = mongoose_metrics_mam_hooks:get_hooks(Host),
ejabberd_hooks:add(Hooks).

spirals() ->
[modMamPrefsSets,
modMamPrefsGets,
modMamArchiveRemoved,
modMamLookups,
modMamForwarded,
modMamArchived,
modMamFlushed,
modMamDropped,
modMamDropped2,
modMamDroppedIQ,
modMamSinglePurges,
modMamMultiplePurges].
12 changes: 0 additions & 12 deletions src/metrics/mongoose_metrics_definitions.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@
modPrivacyStanzaDenied,
modPrivacyStanzaBlocked,
modPrivacyStanzaAll,
modMamPrefsSets,
modMamPrefsGets,
modMamArchiveRemoved,
modMamLookups,
modMamForwarded,
modMamArchived,
modMamFlushed,
modMamDropped,
modMamDropped2,
modMamDroppedIQ,
modMamSinglePurges,
modMamMultiplePurges,
modMucMamPrefsSets,
modMucMamPrefsGets,
modMucMamArchiveRemoved,
Expand Down
3 changes: 1 addition & 2 deletions src/metrics/mongoose_metrics_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit 0a340f8

Please sign in to comment.