Compat windows (#2665)

This commit is contained in:
Gilbert 2019-07-05 23:10:13 +08:00 committed by turtleDeng
parent 61d64cbb83
commit 70be888f3b
3 changed files with 19 additions and 9 deletions

View File

@ -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).

View File

@ -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} ->

View File

@ -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].