diff --git a/apps/emqx_recon/src/emqx_recon_cli.erl b/apps/emqx_modules/src/emqx_mod_recon.erl similarity index 85% rename from apps/emqx_recon/src/emqx_recon_cli.erl rename to apps/emqx_modules/src/emqx_mod_recon.erl index b4e3a52ab..38d046b10 100644 --- a/apps/emqx_recon/src/emqx_recon_cli.erl +++ b/apps/emqx_modules/src/emqx_mod_recon.erl @@ -14,13 +14,34 @@ %% limitations under the License. %%-------------------------------------------------------------------- --module(emqx_recon_cli). +-module(emqx_mod_recon). --export([ cmd/1 - , load/0 - , unload/0 +-behaviour(emqx_gen_mod). + +%% emqx_gen_mod callbacks +-export([ load/1 + , unload/1 + , description/0 ]). +-export([cmd/1]). + + +%%-------------------------------------------------------------------- +%% Load/Unload +%%-------------------------------------------------------------------- + +-spec(load(list()) -> ok). +load(_Env) -> + load(). + +-spec(unload(list()) -> ok). +unload(_Env) -> + unload(). + +description() -> + "EMQ X Recon Module". + load() -> emqx_ctl:register_command(recon, {?MODULE, cmd}, []). @@ -69,4 +90,3 @@ remote_load(Module) -> remote_load(nodes(), Module). %% after OTP 23, it crashes with 'badarg' error remote_load([], _Module) -> ok; remote_load(Nodes, Module) -> recon:remote_load(Nodes, Module). - diff --git a/apps/emqx_recon/.gitignore b/apps/emqx_recon/.gitignore deleted file mode 100644 index 3576f6e23..000000000 --- a/apps/emqx_recon/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -.rebar -.eunit -deps -!deps/.placeholder -*.o -*.beam -*.plt -erl_crash.dump -ebin -!ebin/.placeholder -.exrc -log/ -*.swp -*.so -.erlang.mk/ -logs/ -ct.coverdata -test/ct.cover.spec -.idea/ -emqx_recon.iml -Mnesia.nonode@nohost/ -data/ -cover/ -emqx_recon.d -eunit.coverdata -.DS_Store -_build/ -rebar.lock -erlang.mk -rebar3.crashdump -.rebar3/ diff --git a/apps/emqx_recon/README.md b/apps/emqx_recon/README.md deleted file mode 100644 index ca163be45..000000000 --- a/apps/emqx_recon/README.md +++ /dev/null @@ -1,61 +0,0 @@ - -emqx-recon -========== - -EMQ X Recon Debug/Optimize Plugin - -emqx_recon.conf -----=---------- - -``` -## Global GC Interval. -## -## Value: Duration -## - h: hour -## - m: minute -## - s: second -## -## Examples: -## - 2h: 2 hours -## - 30m: 30 minutes -## - 20s: 20 seconds -## -## Defaut: 5m -recon.gc_interval = 5m -``` - -Load the Plugin ---------------- - -``` -./bin/emqx_ctl plugins load emqx_recon -``` - -Commands --------- - -``` -./bin/emqx_ctl recon - -recon memory #recon_alloc:memory/2 -recon allocated #recon_alloc:memory(allocated_types, current|max) -recon bin_leak #recon:bin_leak(100) -recon node_stats #recon:node_stats(10, 1000) -recon remote_load Mod #recon:remote_load(Mod) -``` - -GC --- - -When the plugin is loaded, global GC will run periodically. - -License -------- - -Apache License Version 2.0 - -Author ------- - -EMQ X Team. - diff --git a/apps/emqx_recon/etc/emqx_recon.conf b/apps/emqx_recon/etc/emqx_recon.conf deleted file mode 100644 index 1ca23bfc2..000000000 --- a/apps/emqx_recon/etc/emqx_recon.conf +++ /dev/null @@ -1,4 +0,0 @@ -##-------------------------------------------------------------------- -## Recon Plugin -##-------------------------------------------------------------------- - diff --git a/apps/emqx_recon/priv/emqx_recon.schema b/apps/emqx_recon/priv/emqx_recon.schema deleted file mode 100644 index 7436d0f8c..000000000 --- a/apps/emqx_recon/priv/emqx_recon.schema +++ /dev/null @@ -1,9 +0,0 @@ -%%-*- mode: erlang -*- -%% emqx-recon config mapping - -%% @doc Global GC Interval -%% {@configurable} -%% {mapping, "recon.gc_interval", "emqx_recon.gc_interval", [ -%% {datatype, {duration, s}} -%% ]}. - diff --git a/apps/emqx_recon/rebar.config b/apps/emqx_recon/rebar.config deleted file mode 100644 index 1a6f20d2b..000000000 --- a/apps/emqx_recon/rebar.config +++ /dev/null @@ -1,18 +0,0 @@ -{deps, [ -%% recon "https://github.com/ferd/recon" at root rebar.config -]}. - -{edoc_opts, [{preprocess, true}]}. -{erl_opts, [warn_unused_vars, - warn_shadow_vars, - warn_unused_import, - warn_obsolete_guard, - debug_info - ]}. - -{xref_checks, [undefined_function_calls, undefined_functions, - locals_not_used, deprecated_function_calls, - warnings_as_errors, deprecated_functions]}. -{cover_enabled, true}. -{cover_opts, [verbose]}. -{cover_export_enabled, true}. diff --git a/apps/emqx_recon/src/emqx_recon.app.src b/apps/emqx_recon/src/emqx_recon.app.src deleted file mode 100644 index e25e2bbc5..000000000 --- a/apps/emqx_recon/src/emqx_recon.app.src +++ /dev/null @@ -1,14 +0,0 @@ -{application, emqx_recon, - [{description, "EMQ X Recon Plugin"}, - {vsn, "4.4.0"}, % strict semver, bump manually! - {modules, []}, - {registered, []}, - {applications, [kernel,stdlib,recon]}, - {mod, {emqx_recon,[]}}, - {env, []}, - {licenses, ["Apache-2.0"]}, - {maintainers, ["EMQ X Team "]}, - {links, [{"Homepage", "https://emqx.io/"}, - {"Github", "https://github.com/emqx/emqx-recon"} - ]} - ]}. diff --git a/apps/emqx_recon/src/emqx_recon.erl b/apps/emqx_recon/src/emqx_recon.erl deleted file mode 100644 index 67039c3ac..000000000 --- a/apps/emqx_recon/src/emqx_recon.erl +++ /dev/null @@ -1,41 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(emqx_recon). - --emqx_plugin(?MODULE). - --behaviour(application). - --export([start/2, stop/1]). - --behaviour(supervisor). - --export([init/1]). - --define(APP, ?MODULE). --define(SUP, emqx_recon_sup). - -start(_StartType, _StartArgs) -> - emqx_recon_cli:load(), - supervisor:start_link({local, ?SUP}, ?MODULE, []). - -stop(_State) -> - emqx_recon_cli:unload(). - -init([]) -> - {ok, {{one_for_one, 10, 100}, []}}. - diff --git a/apps/emqx_recon/test/emqx_recon_SUITE.erl b/apps/emqx_recon/test/emqx_recon_SUITE.erl deleted file mode 100644 index 2abf8f709..000000000 --- a/apps/emqx_recon/test/emqx_recon_SUITE.erl +++ /dev/null @@ -1,114 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(emqx_recon_SUITE). - --compile(nowarn_export_all). --compile(export_all). - --include_lib("eunit/include/eunit.hrl"). - --define(output_patterns(V), ((V)++"")). - -all() -> [{group, cli}]. - -groups() -> - [{cli, [sequence], - [cli_memory, - cli_allocated, - cli_bin_leak, - cli_node_stats, - cli_remote_load, - cli_usage]} - ]. - -init_per_suite(Config) -> - emqx_ct_helpers:start_apps([emqx_recon]), - Config. - -end_per_suite(_Config) -> - emqx_ct_helpers:stop_apps([emqx_recon]). - -cli_memory(_) -> - mock_print(), - Output = emqx_recon_cli:cmd(["memory"]), - Zip = lists:zip(Output, [ ?output_patterns("usage/current") - , ?output_patterns("usage/max") - , ?output_patterns("used/current") - , ?output_patterns("used/max") - , ?output_patterns("allocated/current") - , ?output_patterns("allocated/max") - , ?output_patterns("unused/current") - , ?output_patterns("unused/max") - ]), - %ct:pal("=======~p", [Zip]), - [?assertMatch({match, _}, re:run(Line, Match, [{capture,all,list}])) - || {Line, Match} <- Zip], - unmock_print(). - -cli_allocated(_) -> - mock_print(), - Output = emqx_recon_cli:cmd(["allocated"]), - Zip = lists:zip(Output, [ ?output_patterns("binary_alloc/current") - , ?output_patterns("driver_alloc/current") - , ?output_patterns("eheap_alloc/current") - , ?output_patterns("ets_alloc/current") - , ?output_patterns("fix_alloc/current") - , ?output_patterns("ll_alloc/current") - , ?output_patterns("sl_alloc/current") - , ?output_patterns("std_alloc/current") - , ?output_patterns("temp_alloc/current") - , ?output_patterns("binary_alloc/max") - , ?output_patterns("driver_alloc/max") - , ?output_patterns("eheap_alloc/max") - , ?output_patterns("ets_alloc/max") - , ?output_patterns("fix_alloc/max") - , ?output_patterns("ll_alloc/max") - , ?output_patterns("sl_alloc/max") - , ?output_patterns("std_alloc/max") - , ?output_patterns("temp_alloc/max") - ]), - ct:pal("=======~p", [Zip]), - [?assertMatch({match, _}, re:run(Line, Match, [{capture,all,list}])) - || {Line, Match} <- Zip], - unmock_print(). - -cli_bin_leak(_) -> - mock_print(), - Output = emqx_recon_cli:cmd(["bin_leak"]), - [?assertMatch({match, _}, re:run(Line, "current_function", [{capture,all,list}])) - || Line <- Output], - unmock_print(). - -cli_node_stats(_) -> - emqx_recon_cli:cmd(["node_stats"]). - -cli_remote_load(_) -> - emqx_recon_cli:cmd(["remote_load", "emqx_recon_cli"]). - -cli_usage(_) -> - emqx_recon_cli:cmd(["usage"]). - -mock_print() -> - catch meck:unload(emqx_ctl), - meck:new(emqx_ctl, [non_strict, passthrough]), - meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end), - meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end), - meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end). - -unmock_print() -> - meck:unload(). - diff --git a/data/loaded_modules.tmpl b/data/loaded_modules.tmpl index f31e47900..8dfe6453e 100644 --- a/data/loaded_modules.tmpl +++ b/data/loaded_modules.tmpl @@ -1 +1,2 @@ {emqx_mod_presence, true}. +{emqx_mod_recon, true}. diff --git a/data/loaded_plugins.tmpl b/data/loaded_plugins.tmpl index 5922f6dc5..c2b6311f2 100644 --- a/data/loaded_plugins.tmpl +++ b/data/loaded_plugins.tmpl @@ -1,7 +1,6 @@ {emqx_management, true}. {emqx_dashboard, true}. {emqx_modules, {{enable_plugin_emqx_modules}}}. -{emqx_recon, {{enable_plugin_emqx_recon}}}. {emqx_retainer, {{enable_plugin_emqx_retainer}}}. {emqx_rule_engine, {{enable_plugin_emqx_rule_engine}}}. {emqx_bridge_mqtt, {{enable_plugin_emqx_bridge_mqtt}}}. diff --git a/rebar.config.erl b/rebar.config.erl index 8ce3aa217..88148818e 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -188,7 +188,6 @@ overlay_vars_rel(RelType) -> [ {enable_plugin_emqx_rule_engine, RelType =:= cloud} , {enable_plugin_emqx_bridge_mqtt, RelType =:= edge} , {enable_plugin_emqx_modules, false} %% modules is not a plugin in ce - , {enable_plugin_emqx_recon, true} , {enable_plugin_emqx_retainer, true} , {vm_args_file, VmArgs} ]. @@ -285,7 +284,6 @@ relx_plugin_apps(ReleaseType) -> , emqx_auth_jwt , emqx_auth_mnesia , emqx_web_hook - , emqx_recon , emqx_rule_engine , emqx_sasl , emqx_statsd