Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start only used metrics #3096

Merged
merged 10 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions doc/modules/mod_mam.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,12 @@ If you'd like to learn more about metrics in MongooseIM, please visit [MongooseI
| `[Host, modMamFlushed]` | spiral | Message was stored in a DB asynchronously. |
| `[Host, modMamForwarded]` | spiral | A message is sent to a client as a part of a MAM query result. |
| `[Host, modMamLookups]` | spiral | A MAM lookup is performed. |
| `[Host, modMamSinglePurges]` | spiral | A single purge request is processed by MAM. |
| `[Host, modMamMultiplePurges]` | spiral | A bulk purge request is processed by MAM. |
| `[Host, modMamPrefsGets]` | spiral | Archiving preferences have been requested by a client. |
| `[Host, modMamPrefsSets]` | spiral | Archiving preferences have been updated by a client. |
| `[Host, modMucMamArchiveRemoved]` | spiral | Room's entire archive is removed. |
| `[Host, modMucMamArchived]` | spiral | A message is stored in room's archive. |
| `[Host, modMucMamForwarded]` | spiral | A message is sent to a client as a part of a MAM query result from MUC room. |
| `[Host, modMucMamLookups]` | spiral | A MAM lookup in MUC room is performed. |
| `[Host, modMucMamSinglePurges]` | spiral | A single purge request for MUC room is processed by MAM. |
| `[Host, modMucMamMultiplePurges]` | spiral | A bulk purge request for MUC room is processed by MAM. |
| `[Host, modMucMamPrefsGets]` | spiral | MUC archiving preferences have been requested by a client. |
| `[Host, modMucMamPrefsSets]` | spiral | MUC archiving preferences have been updated by a client. |
| `[Host, mod_mam_rdbms_async_pool_writer, per_message_flush_time]` | histogram | Average time per message insert measured in an async MAM worker. |
Expand Down
1 change: 0 additions & 1 deletion doc/operation-and-maintenance/MongooseIM-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ As a result it makes more sense to maintain a list of the most relevant or usefu

| Name | Type | Description (when it gets incremented) |
| ---- | ---- | -------------------------------------- |
| `[Host, sessionAuthAnonymous]` | spiral | A client authenticates anonymously. |
| `[Host, sessionAuthFails]` | spiral | A client failed to authenticate. |
| `[Host, sessionCount]` | counter | Number of active sessions. |
| `[Host, sessionLogouts]` | spiral | A client session is closed. |
Expand Down
58 changes: 38 additions & 20 deletions src/mam/mod_mam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -210,31 +210,15 @@ start(Host, Opts) ->
?MODULE, process_mam_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_06,
?MODULE, process_mam_iq, IQDisc),
ejabberd_hooks:add(user_send_packet, Host, ?MODULE, user_send_packet, 90),
ejabberd_hooks:add(rest_user_send_packet, Host, ?MODULE, user_send_packet, 90),
ejabberd_hooks:add(filter_local_packet, Host, ?MODULE, filter_packet, 90),
ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 50),
ejabberd_hooks:add(anonymous_purge_hook, Host, ?MODULE, remove_user, 50),
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),
ejabberd_hooks:add(hooks(Host)),
ensure_metrics(Host),
ok.


-spec stop(Host :: jid:server()) -> any().
stop(Host) ->
?LOG_INFO(#{what => mam_stopping}),
ejabberd_hooks:delete(sm_filter_offline_message, Host, ?MODULE, sm_filter_offline_message, 50),
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE, user_send_packet, 90),
ejabberd_hooks:delete(rest_user_send_packet, Host, ?MODULE, user_send_packet, 90),
ejabberd_hooks:delete(filter_local_packet, Host, ?MODULE, filter_packet, 90),
ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50),
ejabberd_hooks:delete(anonymous_purge_hook, Host, ?MODULE, remove_user, 50),
ejabberd_hooks:delete(amp_determine_strategy, Host, ?MODULE, determine_amp_strategy, 20),
ejabberd_hooks:delete(get_personal_data, Host, ?MODULE, get_personal_data, 50),
ejabberd_hooks:delete(hooks(Host)),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_04),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_06),
[mod_disco:unregister_feature(Host, Feature) || Feature <- features(?MODULE, Host)],
Expand Down Expand Up @@ -684,5 +668,39 @@ 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).

-spec hooks(jid:lserver()) -> [ejabberd_hooks:hook()].
hooks(Host) ->
[{user_send_packet, Host, ?MODULE, user_send_packet, 90},
{rest_user_send_packet, Host, ?MODULE, user_send_packet, 90},
{filter_local_packet, Host, ?MODULE, filter_packet, 90},
{remove_user, Host, ?MODULE, remove_user, 50},
{anonymous_purge_hook, Host, ?MODULE, remove_user, 50},
{amp_determine_strategy, Host, ?MODULE, determine_amp_strategy, 20},
{sm_filter_offline_message, Host, ?MODULE, sm_filter_offline_message, 50},
{get_personal_data, Host, ?MODULE, get_personal_data, 50}
| mongoose_metrics_mam_hooks:get_mam_hooks(Host)].


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()).

spirals() ->
[modMamPrefsSets,
modMamPrefsGets,
modMamArchiveRemoved,
modMamLookups,
modMamForwarded,
modMamArchived,
modMamFlushed,
modMamDropped,
modMamDropped2,
modMamDroppedIQ].
33 changes: 26 additions & 7 deletions src/mam/mod_mam_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,16 @@ start(Host, Opts) ->
?MODULE, room_process_mam_iq, IQDisc),
gen_iq_handler:add_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM_06,
?MODULE, room_process_mam_iq, IQDisc),
ejabberd_hooks:add(filter_room_packet, MUCHost, ?MODULE,
filter_room_packet, 90),
ejabberd_hooks:add(forget_room, MUCHost, ?MODULE, forget_room, 90),
ejabberd_hooks:add(get_personal_data, Host, ?MODULE, get_personal_data, 50),
ejabberd_hooks:add(hooks(Host, MUCHost)),
ensure_metrics(Host),
ok.

-spec stop(Host :: jid:server()) -> any().

stop(Host) ->
MUCHost = gen_mod:get_module_opt_subhost(Host, mod_mam_muc, mod_muc:default_host()),
?LOG_DEBUG(#{what => mam_muc_stopping}),
ejabberd_hooks:delete(filter_room_packet, MUCHost, ?MODULE, filter_room_packet, 90),
ejabberd_hooks:delete(forget_room, MUCHost, ?MODULE, forget_room, 90),
ejabberd_hooks:delete(get_personal_data, Host, ?MODULE, get_personal_data, 50),
ejabberd_hooks:delete(hooks(Host, MUCHost)),
gen_iq_handler:remove_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM_04),
gen_iq_handler:remove_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM_06),
[mod_disco:unregister_feature(MUCHost, Feature) || Feature <- features(?MODULE, Host)],
Expand Down Expand Up @@ -605,3 +601,26 @@ is_archivable_message(MUCHost, Dir, Packet) ->
{M, F} = mod_mam_params:is_archivable_message_fun(?MODULE, Host),
ArchiveChatMarkers = mod_mam_params:archive_chat_markers(?MODULE, Host),
erlang:apply(M, F, [?MODULE, Dir, Packet, ArchiveChatMarkers]).

-spec hooks(jid:lserver(), jid:lserver()) -> [ejabberd_hooks:hook()].
hooks(Host, MUCHost) ->
[{filter_room_packet, MUCHost, ?MODULE, filter_room_packet, 90},
{forget_room, MUCHost, ?MODULE, forget_room, 90},
{get_personal_data, Host, ?MODULE, get_personal_data, 50}
| mongoose_metrics_mam_hooks:get_mam_muc_hooks(Host)].

ensure_metrics(Host) ->
lists:foreach(fun(Name) ->
mongoose_metrics:ensure_metric(Host, Name, spiral)
end,
spirals()).

spirals() ->
[modMucMamPrefsSets,
modMucMamPrefsGets,
modMucMamArchiveRemoved,
modMucMamLookups,
modMucMamForwarded,
modMucMamArchived,
modMucMamFlushed,
modMucMamDroppedIQ].
1 change: 0 additions & 1 deletion src/metrics/mongoose_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ filter_hook(mam_get_prefs) -> skip;
filter_hook(mam_set_prefs) -> skip;
filter_hook(mam_remove_archive) -> skip;
filter_hook(mam_archive_message) -> skip;
filter_hook(mam_flush_messages) -> skip;
filter_hook(mam_muc_get_prefs) -> skip;
filter_hook(mam_muc_set_prefs) -> skip;
filter_hook(mam_muc_remove_archive) -> skip;
Expand Down
28 changes: 1 addition & 27 deletions src/metrics/mongoose_metrics_definitions.hrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-define(GENERAL_SPIRALS, [
sessionSuccessfulLogins,
sessionAuthAnonymous,
sessionAuthFails,
sessionLogouts,
xmppMessageSent,
Expand All @@ -18,8 +17,6 @@
xmppErrorIq,
xmppErrorMessage,
xmppErrorPresence,
modGlobalDistribMessagesSent,
modGlobalDistribMessagesReceived,
modRosterSets,
modRosterGets,
modPresenceSubscriptions,
Expand All @@ -34,30 +31,7 @@
modPrivacyGets,
modPrivacyStanzaDenied,
modPrivacyStanzaBlocked,
modPrivacyStanzaAll,
modMamPrefsSets,
modMamPrefsGets,
modMamArchiveRemoved,
modMamLookups,
modMamForwarded,
modMamArchived,
modMamFlushed,
modMamDropped,
modMamDropped2,
modMamDroppedIQ,
modMamSinglePurges,
modMamMultiplePurges,
modMucMamPrefsSets,
modMucMamPrefsGets,
modMucMamArchiveRemoved,
modMucMamLookups,
modMucMamForwarded,
modMucMamArchived,
modMucMamFlushed,
modMucMamSinglePurges,
modMucMamMultiplePurges,
modCSIInactive,
modCSIActive
modPrivacyStanzaAll
]).

-define(TOTAL_COUNTERS, [
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
17 changes: 12 additions & 5 deletions src/metrics/mongoose_metrics_mam_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
-include("mongoose.hrl").
-include("jlib.hrl").

-export([get_hooks/1]).
-export([get_mam_hooks/1,
get_mam_muc_hooks/1]).

%%-------------------
%% Internal exports
Expand All @@ -33,15 +34,21 @@
%% Implementation
%%-------------------

%% @doc Here will be declared which hooks should be registered
-spec get_hooks(_) -> [ejabberd_hooks:hook(), ...].
get_hooks(Host) ->
%% @doc Here will be declared which hooks should be registered when mod_mam is enabled.
-spec get_mam_hooks(_) -> [ejabberd_hooks:hook(), ...].
get_mam_hooks(Host) ->
[
{mam_set_prefs, Host, ?MODULE, mam_set_prefs, 50},
{mam_get_prefs, Host, ?MODULE, mam_get_prefs, 50},
{mam_archive_message, Host, ?MODULE, mam_archive_message, 50},
{mam_remove_archive, Host, ?MODULE, mam_remove_archive, 50},
{mam_lookup_messages, Host, ?MODULE, mam_lookup_messages, 100},
{mam_lookup_messages, Host, ?MODULE, mam_lookup_messages, 100}
].

%% @doc Here will be declared which hooks should be registered when mod_mam_muc is enabled.
-spec get_mam_muc_hooks(_) -> [ejabberd_hooks:hook(), ...].
get_mam_muc_hooks(Host) ->
[
{mam_muc_set_prefs, Host, ?MODULE, mam_muc_set_prefs, 50},
{mam_muc_get_prefs, Host, ?MODULE, mam_muc_get_prefs, 50},
{mam_muc_archive_message, Host, ?MODULE, mam_muc_archive_message, 50},
Expand Down
5 changes: 5 additions & 0 deletions src/mod_csi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
start(Host, _Opts) ->
[ejabberd_hooks:add(Name, Host, Module, Function, Priority) ||
{Name, Module, Function, Priority} <- hooks()],
ensure_metrics(Host),
ok.

stop(Host) ->
Expand All @@ -39,6 +40,10 @@ config_spec() ->
hooks() ->
[{c2s_stream_features, ?MODULE, add_csi_feature, 60}].

ensure_metrics(Host) ->
mongoose_metrics:ensure_metric(Host, [Host, modCSIInactive], spiral),
mongoose_metrics:ensure_metric(Host, [Host, modCSIInactive], spiral).

add_csi_feature(Acc, _Host) ->
lists:keystore(<<"csi">>, #xmlel.name, Acc, csi()).

Expand Down