fix(emqx_os_mon): ensure alarm is deactivated on unsupported platforms
This commit is contained in:
parent
0400638f71
commit
1bebbd6ee5
|
@ -272,8 +272,9 @@ merge_update_actions(App, Changes, Vsns, PrevVersion) ->
|
||||||
end,
|
end,
|
||||||
Vsns).
|
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
|
%% say current version is 1.1.3, and the compare base is version 1.1.1,
|
||||||
%% we may skip merging instructions for 1.1.2 (it's never used)
|
%% 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) ->
|
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
|
case is_app_external(App) andalso parse_version_number(Vsn) of
|
||||||
{ok, VsnTuple} ->
|
{ok, VsnTuple} ->
|
||||||
|
@ -287,7 +288,7 @@ is_skipped_version(App, Vsn, PrevVersion) when is_list(Vsn) andalso is_list(Prev
|
||||||
false
|
false
|
||||||
end;
|
end;
|
||||||
is_skipped_version(_App, _Vsn, _PrevVersion) ->
|
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
|
%% return 'false' to be on the safe side
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
|
|
@ -115,15 +115,15 @@ init([Opts]) ->
|
||||||
%% make sure memsup will not emit system memory alarms
|
%% make sure memsup will not emit system memory alarms
|
||||||
memsup:set_sysmem_high_watermark(1),
|
memsup:set_sysmem_high_watermark(1),
|
||||||
set_procmem_high_watermark(proplists:get_value(procmem_high_watermark, Opts)),
|
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)),
|
SysHW = resolve_watermark(proplists:get_value(sysmem_high_watermark, Opts)),
|
||||||
St = ensure_check_timer(#{cpu_high_watermark => proplists:get_value(cpu_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_low_watermark => proplists:get_value(cpu_low_watermark, Opts),
|
||||||
cpu_check_interval => proplists:get_value(cpu_check_interval, Opts),
|
cpu_check_interval => proplists:get_value(cpu_check_interval, Opts),
|
||||||
sysmem_high_watermark => SysHW,
|
sysmem_high_watermark => SysHW,
|
||||||
mem_check_interval => MemCehckInterval,
|
mem_check_interval => MemCheckInterval,
|
||||||
timer => undefined}),
|
timer => undefined}),
|
||||||
ok = do_set_mem_check_interval(MemCehckInterval),
|
ok = do_set_mem_check_interval(MemCheckInterval),
|
||||||
%% update immediately after start/restart
|
%% update immediately after start/restart
|
||||||
ok = update_mem_alarm_status(SysHW),
|
ok = update_mem_alarm_status(SysHW),
|
||||||
{ok, ensure_mem_check_timer(St)}.
|
{ok, ensure_mem_check_timer(St)}.
|
||||||
|
@ -165,8 +165,6 @@ handle_call(Req, _From, State) ->
|
||||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||||
{reply, ignored, State}.
|
{reply, ignored, State}.
|
||||||
|
|
||||||
handle_cast(upgrade, State) ->
|
|
||||||
{noreply, State};
|
|
||||||
handle_cast(Msg, State) ->
|
handle_cast(Msg, State) ->
|
||||||
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
@ -234,7 +232,9 @@ ensure_mem_check_timer(State) ->
|
||||||
mem_check_interval => Interval
|
mem_check_interval => Interval
|
||||||
};
|
};
|
||||||
false ->
|
false ->
|
||||||
State
|
State#{mem_check_timer => undefined,
|
||||||
|
mem_check_interval => Interval
|
||||||
|
}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
resolve_mem_check_interval(#{mem_check_interval := Seconds}) when is_integer(Seconds) ->
|
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.
|
W.
|
||||||
|
|
||||||
update_mem_alarm_status(SysHW) ->
|
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(),
|
Usage = current_sysmem_percent(),
|
||||||
case Usage > SysHW of
|
case Usage > SysHW of
|
||||||
true ->
|
true ->
|
||||||
|
|
Loading…
Reference in New Issue