fix(emqx_os_mon): ensure alarm is deactivated on unsupported platforms

This commit is contained in:
Zaiming (Stone) Shi 2022-05-25 16:13:33 +02:00
parent 0400638f71
commit 1bebbd6ee5
2 changed files with 19 additions and 9 deletions

View File

@ -272,8 +272,9 @@ merge_update_actions(App, Changes, Vsns, PrevVersion) ->
end,
Vsns).
%% say current version is 1.1.2, and the compare baes is version 1.1.1, but there is a 1.1.2 in appup
%% we may skip merging instructions for 1.1.2 (it's never used)
%% say current version is 1.1.3, and the compare base is version 1.1.1,
%% but there is a 1.1.2 in appup we may skip merging instructions for
%% 1.1.2 because it's not used and no way to know what has been changed
is_skipped_version(App, Vsn, PrevVersion) when is_list(Vsn) andalso is_list(PrevVersion) ->
case is_app_external(App) andalso parse_version_number(Vsn) of
{ok, VsnTuple} ->
@ -287,7 +288,7 @@ is_skipped_version(App, Vsn, PrevVersion) when is_list(Vsn) andalso is_list(Prev
false
end;
is_skipped_version(_App, _Vsn, _PrevVersion) ->
%% if app version is a regexp, we don't konw for sure
%% if app version is a regexp, we don't know for sure
%% return 'false' to be on the safe side
false.

View File

@ -115,15 +115,15 @@ init([Opts]) ->
%% make sure memsup will not emit system memory alarms
memsup:set_sysmem_high_watermark(1),
set_procmem_high_watermark(proplists:get_value(procmem_high_watermark, Opts)),
MemCehckInterval = do_resolve_mem_check_interval(proplists:get_value(mem_check_interval, Opts)),
MemCheckInterval = do_resolve_mem_check_interval(proplists:get_value(mem_check_interval, Opts)),
SysHW = resolve_watermark(proplists:get_value(sysmem_high_watermark, Opts)),
St = ensure_check_timer(#{cpu_high_watermark => proplists:get_value(cpu_high_watermark, Opts),
cpu_low_watermark => proplists:get_value(cpu_low_watermark, Opts),
cpu_check_interval => proplists:get_value(cpu_check_interval, Opts),
sysmem_high_watermark => SysHW,
mem_check_interval => MemCehckInterval,
mem_check_interval => MemCheckInterval,
timer => undefined}),
ok = do_set_mem_check_interval(MemCehckInterval),
ok = do_set_mem_check_interval(MemCheckInterval),
%% update immediately after start/restart
ok = update_mem_alarm_status(SysHW),
{ok, ensure_mem_check_timer(St)}.
@ -165,8 +165,6 @@ handle_call(Req, _From, State) ->
?LOG(error, "Unexpected call: ~p", [Req]),
{reply, ignored, State}.
handle_cast(upgrade, State) ->
{noreply, State};
handle_cast(Msg, State) ->
?LOG(error, "Unexpected cast: ~p", [Msg]),
{noreply, State}.
@ -234,7 +232,9 @@ ensure_mem_check_timer(State) ->
mem_check_interval => Interval
};
false ->
State
State#{mem_check_timer => undefined,
mem_check_interval => Interval
}
end.
resolve_mem_check_interval(#{mem_check_interval := Seconds}) when is_integer(Seconds) ->
@ -281,6 +281,15 @@ resolve_watermark(W) when W > 0 andalso W =< 100 ->
W.
update_mem_alarm_status(SysHW) ->
case is_sysmem_check_supported() of
true ->
do_update_mem_alarm_status(SysHW);
false ->
%% in case the old alarm is activated
ok = emqx_alarm:ensure_deactivated(high_system_memory_usage, #{reason => disabled})
end.
do_update_mem_alarm_status(SysHW) ->
Usage = current_sysmem_percent(),
case Usage > SysHW of
true ->