Remove the 'emqx_time' module and use 'erlang:system_time/1'
This commit is contained in:
parent
223163d5b9
commit
605a03453e
|
@ -158,7 +158,7 @@ encode_alarm({AlarmId, #alarm{severity = Severity,
|
||||||
{desc, [{severity, Severity},
|
{desc, [{severity, Severity},
|
||||||
{title, iolist_to_binary(Title)},
|
{title, iolist_to_binary(Title)},
|
||||||
{summary, iolist_to_binary(Summary)},
|
{summary, iolist_to_binary(Summary)},
|
||||||
{timestamp, emqx_time:now_ms(Ts)}]}]);
|
{timestamp, emqx_misc:now_to_secs(Ts)}]}]);
|
||||||
encode_alarm({AlarmId, undefined}) ->
|
encode_alarm({AlarmId, undefined}) ->
|
||||||
emqx_json:safe_encode([{id, maybe_to_binary(AlarmId)}]);
|
emqx_json:safe_encode([{id, maybe_to_binary(AlarmId)}]);
|
||||||
encode_alarm({AlarmId, AlarmDesc}) ->
|
encode_alarm({AlarmId, AlarmDesc}) ->
|
||||||
|
|
|
@ -99,7 +99,7 @@ detect(#{clientid := ClientId, peerhost := PeerHost},
|
||||||
%% Create a flapping record.
|
%% Create a flapping record.
|
||||||
Flapping = #flapping{clientid = ClientId,
|
Flapping = #flapping{clientid = ClientId,
|
||||||
peerhost = PeerHost,
|
peerhost = PeerHost,
|
||||||
started_at = emqx_time:now_ms(),
|
started_at = erlang:system_time(millisecond),
|
||||||
detect_cnt = 1
|
detect_cnt = 1
|
||||||
},
|
},
|
||||||
true = ets:insert(?FLAPPING_TAB, Flapping),
|
true = ets:insert(?FLAPPING_TAB, Flapping),
|
||||||
|
@ -111,7 +111,7 @@ detect(#{clientid := ClientId, peerhost := PeerHost},
|
||||||
get_policy() ->
|
get_policy() ->
|
||||||
emqx:get_env(flapping_detect_policy, ?DEFAULT_DETECT_POLICY).
|
emqx:get_env(flapping_detect_policy, ?DEFAULT_DETECT_POLICY).
|
||||||
|
|
||||||
now_diff(TS) -> emqx_time:now_ms() - TS.
|
now_diff(TS) -> erlang:system_time(millisecond) - TS.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
@ -143,7 +143,7 @@ handle_cast({detected, Flapping = #flapping{clientid = ClientId,
|
||||||
[ClientId, esockd_net:ntoa(PeerHost), DetectCnt, Duration]),
|
[ClientId, esockd_net:ntoa(PeerHost), DetectCnt, Duration]),
|
||||||
%% Banned.
|
%% Banned.
|
||||||
BannedFlapping = Flapping#flapping{clientid = {banned, ClientId},
|
BannedFlapping = Flapping#flapping{clientid = {banned, ClientId},
|
||||||
banned_at = emqx_time:now_ms()
|
banned_at = erlang:system_time(millisecond)
|
||||||
},
|
},
|
||||||
alarm_handler:set_alarm({{flapping_detected, ClientId}, BannedFlapping}),
|
alarm_handler:set_alarm({{flapping_detected, ClientId}, BannedFlapping}),
|
||||||
ets:insert(?FLAPPING_TAB, BannedFlapping);
|
ets:insert(?FLAPPING_TAB, BannedFlapping);
|
||||||
|
@ -160,7 +160,8 @@ handle_cast(Msg, State) ->
|
||||||
|
|
||||||
handle_info({timeout, TRef, expire_flapping}, State = #{tref := TRef}) ->
|
handle_info({timeout, TRef, expire_flapping}, State = #{tref := TRef}) ->
|
||||||
with_flapping_tab(fun expire_flapping/2,
|
with_flapping_tab(fun expire_flapping/2,
|
||||||
[emqx_time:now_ms(), get_policy()]),
|
[erlang:system_time(millisecond),
|
||||||
|
get_policy()]),
|
||||||
{noreply, ensure_timer(State#{tref => undefined}), hibernate};
|
{noreply, ensure_timer(State#{tref => undefined}), hibernate};
|
||||||
|
|
||||||
handle_info(Info, State) ->
|
handle_info(Info, State) ->
|
||||||
|
|
|
@ -62,7 +62,7 @@ on_client_connected(ClientInfo, ConnAck, ConnInfo, Env) ->
|
||||||
connack => ConnAck,
|
connack => ConnAck,
|
||||||
clean_start => CleanStart,
|
clean_start => CleanStart,
|
||||||
expiry_interval => ExpiryInterval,
|
expiry_interval => ExpiryInterval,
|
||||||
ts => emqx_time:now_ms()
|
ts => erlang:system_time(millisecond)
|
||||||
},
|
},
|
||||||
case emqx_json:safe_encode(Presence) of
|
case emqx_json:safe_encode(Presence) of
|
||||||
{ok, Payload} ->
|
{ok, Payload} ->
|
||||||
|
@ -78,7 +78,7 @@ on_client_disconnected(ClientInfo, Reason, ConnInfo, Env) ->
|
||||||
Presence = #{clientid => ClientId,
|
Presence = #{clientid => ClientId,
|
||||||
username => Username,
|
username => Username,
|
||||||
reason => reason(Reason),
|
reason => reason(Reason),
|
||||||
ts => emqx_time:now_ms()
|
ts => erlang:system_time(millisecond)
|
||||||
},
|
},
|
||||||
case emqx_json:safe_encode(Presence) of
|
case emqx_json:safe_encode(Presence) of
|
||||||
{ok, Payload} ->
|
{ok, Payload} ->
|
||||||
|
|
Loading…
Reference in New Issue