Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
19fdf3b77a
|
@ -152,6 +152,7 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Banned
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-type(banned_who() :: {client_id, binary()}
|
||||
| {username, binary()}
|
||||
| {ip_address, inet:ip_address()}).
|
||||
|
@ -165,3 +166,13 @@
|
|||
}).
|
||||
|
||||
-endif.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Compatible with Windows
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-define(compat_windows(Expression, Default),
|
||||
case os:type() of
|
||||
{win32, nt} -> Default;
|
||||
_Unix -> Expression
|
||||
end).
|
||||
|
|
|
@ -188,8 +188,24 @@ update_expiry(Msg) -> Msg.
|
|||
|
||||
%% @doc Message to map
|
||||
-spec(to_map(emqx_types:message()) -> map()).
|
||||
to_map(Msg) ->
|
||||
maps:from_list(to_list(Msg)).
|
||||
to_map(#message{
|
||||
id = Id,
|
||||
qos = QoS,
|
||||
from = From,
|
||||
flags = Flags,
|
||||
headers = Headers,
|
||||
topic = Topic,
|
||||
payload = Payload,
|
||||
timestamp = Timestamp
|
||||
}) ->
|
||||
#{id => Id,
|
||||
qos => QoS,
|
||||
from => From,
|
||||
flags => Flags,
|
||||
headers => Headers,
|
||||
topic => Topic,
|
||||
payload => Payload,
|
||||
timestamp => Timestamp}.
|
||||
|
||||
%% @doc Message to tuple list
|
||||
-spec(to_list(emqx_types:message()) -> map()).
|
||||
|
|
|
@ -47,10 +47,7 @@
|
|||
|
||||
-define(OS_MON, ?MODULE).
|
||||
|
||||
-define(compat_windows(Expression), case os:type() of
|
||||
{win32, nt} -> windows;
|
||||
_Unix -> Expression
|
||||
end).
|
||||
-include("emqx.hrl").
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% API
|
||||
|
@ -100,7 +97,7 @@ set_procmem_high_watermark(Float) ->
|
|||
%%------------------------------------------------------------------------------
|
||||
|
||||
init([Opts]) ->
|
||||
_ = ?compat_windows(cpu_sup:util()),
|
||||
_ = ?compat_windows(cpu_sup:util(), windows),
|
||||
set_mem_check_interval(proplists:get_value(mem_check_interval, Opts, 60)),
|
||||
set_sysmem_high_watermark(proplists:get_value(sysmem_high_watermark, Opts, 0.70)),
|
||||
set_procmem_high_watermark(proplists:get_value(procmem_high_watermark, Opts, 0.05)),
|
||||
|
@ -135,7 +132,7 @@ handle_info({timeout, Timer, check}, State = #{timer := Timer,
|
|||
cpu_high_watermark := CPUHighWatermark,
|
||||
cpu_low_watermark := CPULowWatermark,
|
||||
is_cpu_alarm_set := IsCPUAlarmSet}) ->
|
||||
case ?compat_windows(cpu_sup:util()) of
|
||||
case ?compat_windows(cpu_sup:util(), windows) of
|
||||
0 ->
|
||||
{noreply, State#{timer := undefined}};
|
||||
{error, Reason} ->
|
||||
|
|
|
@ -214,7 +214,7 @@ attrs(#state{clean_start = CleanStart,
|
|||
{binding, binding(ConnPid)},
|
||||
{client_id, ClientId},
|
||||
{username, Username},
|
||||
{expiry_interval, ExpiryInterval div 1000},
|
||||
{expiry_interval, ExpiryInterval},
|
||||
{created_at, CreatedAt}].
|
||||
|
||||
-spec(stats(spid() | #state{}) -> list({atom(), non_neg_integer()})).
|
||||
|
|
|
@ -159,6 +159,8 @@
|
|||
sndbuf,
|
||||
tos]).
|
||||
|
||||
-include("emqx.hrl").
|
||||
|
||||
schedulers() ->
|
||||
erlang:system_info(schedulers).
|
||||
|
||||
|
@ -167,9 +169,9 @@ microsecs() ->
|
|||
(Mega * 1000000 + Sec) * 1000000 + Micro.
|
||||
|
||||
loads() ->
|
||||
[{load1, ftos(cpu_sup:avg1()/256)},
|
||||
{load5, ftos(cpu_sup:avg5()/256)},
|
||||
{load15, ftos(cpu_sup:avg15()/256)}].
|
||||
[{load1, ftos(?compat_windows(cpu_sup:avg1()/256, 0.0))},
|
||||
{load5, ftos(?compat_windows(cpu_sup:avg5()/256, 0.0))},
|
||||
{load15, ftos(?compat_windows(cpu_sup:avg15()/256, 0.0))}].
|
||||
|
||||
get_system_info() ->
|
||||
[{Key, format_system_info(Key, get_system_info(Key))} || Key <- ?SYSTEM_INFO].
|
||||
|
|
Loading…
Reference in New Issue