Skip to content

Commit

Permalink
Fix alarm report bug (#2332)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercl authored and turtleDeng committed Mar 21, 2019
1 parent 3a2f6d5 commit e732062
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/emqx_os_mon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ init([Opts]) ->
{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_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) ->
{reply, maps:get(cpu_check_interval, State, undefined), State};
Expand All @@ -122,7 +123,8 @@ handle_cast(_Request, State) ->

handle_info({timeout, Timer, check}, State = #{timer := Timer,
cpu_high_watermark := CPUHighWatermark,
cpu_low_watermark := CPULowWatermark}) ->
cpu_low_watermark := CPULowWatermark,
is_cpu_alarm_set := IsCPUAlarmSet}) ->
case cpu_sup:util() of
0 ->
{noreply, State#{timer := undefined}};
Expand All @@ -131,10 +133,13 @@ handle_info({timeout, Timer, check}, State = #{timer := Timer,
{noreply, ensure_check_timer(State)};
Busy when Busy / 100 >= CPUHighWatermark ->
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 ->
alarm_handler:clear_alarm(cpu_high_watermark),
{noreply, ensure_check_timer(State)}
case IsCPUAlarmSet of
true -> alarm_handler:clear_alarm(cpu_high_watermark);
false -> ok
end,
{noreply, ensure_check_timer(State#{is_cpu_alarm_set := false})}
end.

terminate(_Reason, #{timer := Timer}) ->
Expand Down
18 changes: 12 additions & 6 deletions src/emqx_vm_mon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ init([Opts]) ->
{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_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) ->
{reply, maps:get(check_interval, State, undefined), State};
Expand All @@ -92,15 +93,20 @@ handle_cast(_Request, State) ->

handle_info({timeout, Timer, check}, State = #{timer := Timer,
process_high_watermark := ProcHighWatermark,
process_low_watermark := ProcLowWatermark}) ->
process_low_watermark := ProcLowWatermark,
is_process_alarm_set := IsProcessAlarmSet}) ->
ProcessCount = erlang:system_info(process_count),
case ProcessCount / erlang:system_info(process_limit) of
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 ->
alarm_handler:clear_alarm(too_many_processes)
end,
{noreply, ensure_check_timer(State)}.
case IsProcessAlarmSet of
true -> alarm_handler:clear_alarm(too_many_processes);
false -> ok
end,
{noreply, ensure_check_timer(State#{is_process_alarm_set := false})}
end.

terminate(_Reason, #{timer := Timer}) ->
emqx_misc:cancel_timer(Timer).
Expand Down

0 comments on commit e732062

Please sign in to comment.