Fix alarm report bug (#2332)
This commit is contained in:
parent
3a2f6d5a6c
commit
e7320620c0
|
@ -97,7 +97,8 @@ init([Opts]) ->
|
||||||
{ok, ensure_check_timer(#{cpu_high_watermark => proplists:get_value(cpu_high_watermark, Opts, 0.80),
|
{ok, ensure_check_timer(#{cpu_high_watermark => proplists:get_value(cpu_high_watermark, Opts, 0.80),
|
||||||
cpu_low_watermark => proplists:get_value(cpu_low_watermark, Opts, 0.60),
|
cpu_low_watermark => proplists:get_value(cpu_low_watermark, Opts, 0.60),
|
||||||
cpu_check_interval => proplists:get_value(cpu_check_interval, Opts, 60),
|
cpu_check_interval => proplists:get_value(cpu_check_interval, Opts, 60),
|
||||||
timer => undefined})}.
|
timer => undefined,
|
||||||
|
is_cpu_alarm_set => false})}.
|
||||||
|
|
||||||
handle_call(get_cpu_check_interval, _From, State) ->
|
handle_call(get_cpu_check_interval, _From, State) ->
|
||||||
{reply, maps:get(cpu_check_interval, State, undefined), State};
|
{reply, maps:get(cpu_check_interval, State, undefined), State};
|
||||||
|
@ -122,7 +123,8 @@ handle_cast(_Request, State) ->
|
||||||
|
|
||||||
handle_info({timeout, Timer, check}, State = #{timer := Timer,
|
handle_info({timeout, Timer, check}, State = #{timer := Timer,
|
||||||
cpu_high_watermark := CPUHighWatermark,
|
cpu_high_watermark := CPUHighWatermark,
|
||||||
cpu_low_watermark := CPULowWatermark}) ->
|
cpu_low_watermark := CPULowWatermark,
|
||||||
|
is_cpu_alarm_set := IsCPUAlarmSet}) ->
|
||||||
case cpu_sup:util() of
|
case cpu_sup:util() of
|
||||||
0 ->
|
0 ->
|
||||||
{noreply, State#{timer := undefined}};
|
{noreply, State#{timer := undefined}};
|
||||||
|
@ -131,10 +133,13 @@ handle_info({timeout, Timer, check}, State = #{timer := Timer,
|
||||||
{noreply, ensure_check_timer(State)};
|
{noreply, ensure_check_timer(State)};
|
||||||
Busy when Busy / 100 >= CPUHighWatermark ->
|
Busy when Busy / 100 >= CPUHighWatermark ->
|
||||||
alarm_handler:set_alarm({cpu_high_watermark, Busy}),
|
alarm_handler:set_alarm({cpu_high_watermark, Busy}),
|
||||||
{noreply, ensure_check_timer(State)};
|
{noreply, ensure_check_timer(State#{is_cpu_alarm_set := true})};
|
||||||
Busy when Busy / 100 < CPULowWatermark ->
|
Busy when Busy / 100 < CPULowWatermark ->
|
||||||
alarm_handler:clear_alarm(cpu_high_watermark),
|
case IsCPUAlarmSet of
|
||||||
{noreply, ensure_check_timer(State)}
|
true -> alarm_handler:clear_alarm(cpu_high_watermark);
|
||||||
|
false -> ok
|
||||||
|
end,
|
||||||
|
{noreply, ensure_check_timer(State#{is_cpu_alarm_set := false})}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
terminate(_Reason, #{timer := Timer}) ->
|
terminate(_Reason, #{timer := Timer}) ->
|
||||||
|
|
|
@ -67,7 +67,8 @@ init([Opts]) ->
|
||||||
{ok, ensure_check_timer(#{check_interval => proplists:get_value(check_interval, Opts, 30),
|
{ok, ensure_check_timer(#{check_interval => proplists:get_value(check_interval, Opts, 30),
|
||||||
process_high_watermark => proplists:get_value(process_high_watermark, Opts, 0.70),
|
process_high_watermark => proplists:get_value(process_high_watermark, Opts, 0.70),
|
||||||
process_low_watermark => proplists:get_value(process_low_watermark, Opts, 0.50),
|
process_low_watermark => proplists:get_value(process_low_watermark, Opts, 0.50),
|
||||||
timer => undefined})}.
|
timer => undefined,
|
||||||
|
is_process_alarm_set => false})}.
|
||||||
|
|
||||||
handle_call(get_check_interval, _From, State) ->
|
handle_call(get_check_interval, _From, State) ->
|
||||||
{reply, maps:get(check_interval, State, undefined), State};
|
{reply, maps:get(check_interval, State, undefined), State};
|
||||||
|
@ -92,15 +93,20 @@ handle_cast(_Request, State) ->
|
||||||
|
|
||||||
handle_info({timeout, Timer, check}, State = #{timer := Timer,
|
handle_info({timeout, Timer, check}, State = #{timer := Timer,
|
||||||
process_high_watermark := ProcHighWatermark,
|
process_high_watermark := ProcHighWatermark,
|
||||||
process_low_watermark := ProcLowWatermark}) ->
|
process_low_watermark := ProcLowWatermark,
|
||||||
|
is_process_alarm_set := IsProcessAlarmSet}) ->
|
||||||
ProcessCount = erlang:system_info(process_count),
|
ProcessCount = erlang:system_info(process_count),
|
||||||
case ProcessCount / erlang:system_info(process_limit) of
|
case ProcessCount / erlang:system_info(process_limit) of
|
||||||
Percent when Percent >= ProcHighWatermark ->
|
Percent when Percent >= ProcHighWatermark ->
|
||||||
alarm_handler:set_alarm({too_many_processes, ProcessCount});
|
alarm_handler:set_alarm({too_many_processes, ProcessCount}),
|
||||||
|
{noreply, ensure_check_timer(State#{is_process_alarm_set := true})};
|
||||||
Percent when Percent < ProcLowWatermark ->
|
Percent when Percent < ProcLowWatermark ->
|
||||||
alarm_handler:clear_alarm(too_many_processes)
|
case IsProcessAlarmSet of
|
||||||
end,
|
true -> alarm_handler:clear_alarm(too_many_processes);
|
||||||
{noreply, ensure_check_timer(State)}.
|
false -> ok
|
||||||
|
end,
|
||||||
|
{noreply, ensure_check_timer(State#{is_process_alarm_set := false})}
|
||||||
|
end.
|
||||||
|
|
||||||
terminate(_Reason, #{timer := Timer}) ->
|
terminate(_Reason, #{timer := Timer}) ->
|
||||||
emqx_misc:cancel_timer(Timer).
|
emqx_misc:cancel_timer(Timer).
|
||||||
|
|
Loading…
Reference in New Issue