fix: remove os_mon application in Windows release

This commit is contained in:
zhongwencool 2023-08-15 16:47:43 +08:00
parent b23da691c0
commit 848eb7e3c3
7 changed files with 49 additions and 31 deletions

View File

@ -14,7 +14,6 @@
esockd, esockd,
cowboy, cowboy,
sasl, sasl,
os_mon,
lc, lc,
hocon, hocon,
emqx_durable_storage emqx_durable_storage

View File

@ -56,7 +56,7 @@ start_link() ->
gen_server:start_link({local, ?OS_MON}, ?MODULE, [], []). gen_server:start_link({local, ?OS_MON}, ?MODULE, [], []).
update(OS) -> update(OS) ->
erlang:send(?MODULE, {monitor_conf_update, OS}). gen_server:cast(?MODULE, {monitor_conf_update, OS}).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% API %% API
@ -110,6 +110,12 @@ handle_call({set_sysmem_high_watermark, New}, _From, #{sysmem_high_watermark :=
handle_call(Req, _From, State) -> handle_call(Req, _From, State) ->
{reply, {error, {unexpected_call, Req}}, State}. {reply, {error, {unexpected_call, Req}}, State}.
handle_cast({monitor_conf_update, OS}, State) ->
cancel_outdated_timer(State),
SysHW = init_os_monitor(OS),
MemRef = start_mem_check_timer(),
CpuRef = start_cpu_check_timer(),
{noreply, #{sysmem_high_watermark => SysHW, mem_time_ref => MemRef, cpu_time_ref => CpuRef}};
handle_cast(Msg, State) -> handle_cast(Msg, State) ->
?SLOG(error, #{msg => "unexpected_cast", cast => Msg}), ?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
{noreply, State}. {noreply, State}.
@ -151,12 +157,6 @@ handle_info({timeout, _Timer, cpu_check}, State) ->
end, end,
Ref = start_cpu_check_timer(), Ref = start_cpu_check_timer(),
{noreply, State#{cpu_time_ref => Ref}}; {noreply, State#{cpu_time_ref => Ref}};
handle_info({monitor_conf_update, OS}, State) ->
cancel_outdated_timer(State),
SysHW = init_os_monitor(OS),
MemRef = start_mem_check_timer(),
CpuRef = start_cpu_check_timer(),
{noreply, #{sysmem_high_watermark => SysHW, mem_time_ref => MemRef, cpu_time_ref => CpuRef}};
handle_info(Info, State) -> handle_info(Info, State) ->
?SLOG(error, #{msg => "unexpected_info", info => Info}), ?SLOG(error, #{msg => "unexpected_info", info => Info}),
{noreply, State}. {noreply, State}.

View File

@ -1582,7 +1582,7 @@ fields("sysmon_os") ->
sc( sc(
hoconsc:union([disabled, duration()]), hoconsc:union([disabled, duration()]),
#{ #{
default => <<"60s">>, default => default_mem_check_interval(),
desc => ?DESC(sysmon_os_mem_check_interval) desc => ?DESC(sysmon_os_mem_check_interval)
} }
)}, )},
@ -3657,3 +3657,9 @@ shared_subscription_strategy() ->
desc => ?DESC(broker_shared_subscription_strategy) desc => ?DESC(broker_shared_subscription_strategy)
} }
)}. )}.
default_mem_check_interval() ->
case emqx_sys_sup:is_os_mon_supported() of
true -> <<"60s">>;
false -> disabled
end.

View File

@ -19,6 +19,7 @@
-behaviour(supervisor). -behaviour(supervisor).
-export([start_link/0]). -export([start_link/0]).
-export([is_os_mon_supported/0]).
-export([init/1]). -export([init/1]).
@ -26,19 +27,27 @@ start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []). supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) -> init([]) ->
Childs = [ OsMon =
case is_os_mon_supported() of
true -> [child_spec(emqx_os_mon)];
false -> []
end,
Children =
[
child_spec(emqx_sys), child_spec(emqx_sys),
child_spec(emqx_alarm), child_spec(emqx_alarm),
child_spec(emqx_sys_mon), child_spec(emqx_sys_mon),
child_spec(emqx_os_mon),
child_spec(emqx_vm_mon) child_spec(emqx_vm_mon)
], ] ++ OsMon,
{ok, {{one_for_one, 10, 100}, Childs}}. {ok, {{one_for_one, 10, 100}, Children}}.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Internal functions %% Internal functions
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
is_os_mon_supported() ->
erlang:function_exported(memsup, get_procmem_high_watermark, 0).
child_spec(Mod) -> child_spec(Mod) ->
child_spec(Mod, []). child_spec(Mod, []).

View File

@ -36,7 +36,6 @@
[ [
emqx, emqx,
emqx_conf, emqx_conf,
esasl, esasl,
observer_cli, observer_cli,
tools, tools,

View File

@ -405,12 +405,13 @@ relx_apps(ReleaseType, Edition) ->
ce -> CEBusinessApps ce -> CEBusinessApps
end, end,
BusinessApps = CommonBusinessApps ++ EditionSpecificApps, BusinessApps = CommonBusinessApps ++ EditionSpecificApps,
ExcludedApps = excluded_apps(ReleaseType), Apps =
SystemApps ++ (SystemApps ++
%% EMQX starts the DB and the business applications: %% EMQX starts the DB and the business applications:
[{App, load} || App <- (DBApps -- ExcludedApps)] ++ [{App, load} || App <- DBApps] ++
[emqx_machine] ++ [emqx_machine] ++
[{App, load} || App <- (BusinessApps -- ExcludedApps)]. [{App, load} || App <- BusinessApps]),
lists:foldl(fun proplists:delete/2, Apps, excluded_apps(ReleaseType)).
excluded_apps(ReleaseType) -> excluded_apps(ReleaseType) ->
OptionalApps = [ OptionalApps = [
@ -418,7 +419,8 @@ excluded_apps(ReleaseType) ->
{bcrypt, provide_bcrypt_release(ReleaseType)}, {bcrypt, provide_bcrypt_release(ReleaseType)},
{jq, is_jq_supported()}, {jq, is_jq_supported()},
{observer, is_app(observer)}, {observer, is_app(observer)},
{mnesia_rocksdb, is_rocksdb_supported()} {mnesia_rocksdb, is_rocksdb_supported()},
{os_mon, provide_os_mon_release()}
], ],
[App || {App, false} <- OptionalApps]. [App || {App, false} <- OptionalApps].
@ -524,6 +526,9 @@ is_debug(VarName) ->
provide_bcrypt_dep() -> provide_bcrypt_dep() ->
not is_win32(). not is_win32().
provide_os_mon_release() ->
not is_win32().
provide_bcrypt_release(ReleaseType) -> provide_bcrypt_release(ReleaseType) ->
provide_bcrypt_dep() andalso ReleaseType =:= cloud. provide_bcrypt_dep() andalso ReleaseType =:= cloud.

View File

@ -156,7 +156,7 @@ persistent_session_builtin_messages_table.label:
sysmon_os_cpu_low_watermark.desc: sysmon_os_cpu_low_watermark.desc:
"""The threshold, as percentage of system CPU load, """The threshold, as percentage of system CPU load,
for how much system cpu can be used before the corresponding alarm is cleared.""" for how much system cpu can be used before the corresponding alarm is cleared. Disabled on Windows platform"""
sysmon_os_cpu_low_watermark.label: sysmon_os_cpu_low_watermark.label:
"""CPU low watermark""" """CPU low watermark"""
@ -278,7 +278,7 @@ fields_ws_opts_mqtt_path.label:
sysmon_os_procmem_high_watermark.desc: sysmon_os_procmem_high_watermark.desc:
"""The threshold, as percentage of system memory, """The threshold, as percentage of system memory,
for how much system memory can be allocated by one Erlang process before for how much system memory can be allocated by one Erlang process before
the corresponding alarm is raised.""" the corresponding alarm is raised. Disabled on Windows platform."""
sysmon_os_procmem_high_watermark.label: sysmon_os_procmem_high_watermark.label:
"""ProcMem high wartermark""" """ProcMem high wartermark"""
@ -389,7 +389,7 @@ fields_tcp_opts_sndbuf.label:
"""TCP send buffer""" """TCP send buffer"""
sysmon_os_mem_check_interval.desc: sysmon_os_mem_check_interval.desc:
"""The time interval for the periodic memory check.""" """The time interval for the periodic memory check. Disabled on Windows platform."""
sysmon_os_mem_check_interval.label: sysmon_os_mem_check_interval.label:
"""Mem check interval""" """Mem check interval"""
@ -742,7 +742,7 @@ common_ssl_opts_schema_keyfile.label:
sysmon_os_cpu_high_watermark.desc: sysmon_os_cpu_high_watermark.desc:
"""The threshold, as percentage of system CPU load, """The threshold, as percentage of system CPU load,
for how much system cpu can be used before the corresponding alarm is raised.""" for how much system cpu can be used before the corresponding alarm is raised. Disabled on Windows platform"""
sysmon_os_cpu_high_watermark.label: sysmon_os_cpu_high_watermark.label:
"""CPU high watermark""" """CPU high watermark"""
@ -798,7 +798,7 @@ fields_ws_opts_proxy_address_header.label:
sysmon_os_sysmem_high_watermark.desc: sysmon_os_sysmem_high_watermark.desc:
"""The threshold, as percentage of system memory, """The threshold, as percentage of system memory,
for how much system memory can be allocated before the corresponding alarm is raised.""" for how much system memory can be allocated before the corresponding alarm is raised. Disabled on Windows platform"""
sysmon_os_sysmem_high_watermark.label: sysmon_os_sysmem_high_watermark.label:
"""SysMem high wartermark""" """SysMem high wartermark"""
@ -1521,7 +1521,7 @@ fields_tcp_opts_send_timeout_close.label:
"""TCP send timeout close""" """TCP send timeout close"""
sysmon_os_cpu_check_interval.desc: sysmon_os_cpu_check_interval.desc:
"""The time interval for the periodic CPU check.""" """The time interval for the periodic CPU check. Disabled on Windows platform."""
sysmon_os_cpu_check_interval.label: sysmon_os_cpu_check_interval.label:
"""The time interval for the periodic CPU check.""" """The time interval for the periodic CPU check."""