Skip to content

Commit

Permalink
Merge pull request #3220 from esl/fix/system_metrics_error
Browse files Browse the repository at this point in the history
Fix system metrics error
  • Loading branch information
chrzaszcz authored Aug 23, 2021
2 parents df72300 + c7fca17 commit 20c296a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/domain/mongoose_domain_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

-export([get_all_static/0,
get_all_outdated/1,
get_domains_by_host_type/1]).
get_domains_by_host_type/1,
domains_count/0]).

-export([for_each_domain/2]).

Expand Down Expand Up @@ -94,6 +95,9 @@ get_all_static() ->
get_domains_by_host_type(HostType) when is_binary(HostType) ->
heads(ets:match(?TABLE, {'$1', HostType, '_'})).

domains_count() ->
ets:info(?TABLE, size).

-spec for_each_domain(host_type(), fun((host_type(), domain())-> any())) -> ok.
for_each_domain(HostType, Func) ->
ets:safe_fixtable(?TABLE, true),
Expand Down
21 changes: 14 additions & 7 deletions src/system_metrics/mongoose_system_metrics_collector.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-module(mongoose_system_metrics_collector).

-include("mongoose.hrl").

-type report_struct() ::
#{
report_name := term(),
Expand All @@ -24,6 +26,7 @@ get_reports(Fun) ->
report_getters() ->
[
fun get_hosts_count/0,
fun get_domains_count/0,
fun get_modules/0,
fun get_number_of_custom_modules/0,
fun get_uptime/0,
Expand All @@ -38,16 +41,20 @@ report_getters() ->
].

get_hosts_count() ->
Hosts = ejabberd_config:get_global_option(hosts),
NumberOfHosts = length(Hosts),
HostTypes = ?ALL_HOST_TYPES,
NumberOfHosts = length(HostTypes),
[#{report_name => hosts, key => count, value => NumberOfHosts}].

get_domains_count() ->
DomainsCount = mongoose_domain_core:domains_count(),
[#{report_name => domains, key => count, value => DomainsCount}].

get_modules() ->
Hosts = ejabberd_config:get_global_option(hosts),
AllModules = lists:flatten([gen_mod:loaded_modules(H) || H <- Hosts]),
HostTypes = ?ALL_HOST_TYPES,
AllModules = lists:flatten([gen_mod:loaded_modules(H) || H <- HostTypes]),
ModulesToReport = filter_behaviour_implementations(lists:usort(AllModules),
mongoose_module_metrics),
ModsWithOpts = [get_modules_metrics(Host, ModulesToReport) || Host <- Hosts],
ModsWithOpts = [get_modules_metrics(Host, ModulesToReport) || Host <- HostTypes],
[report_module_with_opts(Mod, Opt) || {Mod, Opt} <- lists:flatten(ModsWithOpts)].

filter_behaviour_implementations(Modules, Behaviour) ->
Expand Down Expand Up @@ -78,9 +85,9 @@ report_module_with_opts(Module, Opts) ->
end,Opts).

get_number_of_custom_modules() ->
Hosts = ejabberd_config:get_global_option(hosts),
HostTypes = ?ALL_HOST_TYPES,
AllModules = lists:flatten(
lists:map(fun gen_mod:loaded_modules/1, Hosts)),
lists:map(fun gen_mod:loaded_modules/1, HostTypes)),
GenMods = filter_behaviour_implementations(AllModules, gen_mod),
GenModsSet = sets:from_list(GenMods),
MetricsModule = filter_behaviour_implementations(AllModules,
Expand Down

0 comments on commit 20c296a

Please sign in to comment.