fix: hide cpu_status if os_check is not supported
This commit is contained in:
parent
b817e03c08
commit
8b23ee86b3
|
@ -390,18 +390,15 @@ compat_windows(Fun) ->
|
||||||
|
|
||||||
compat_windows(Fun, Args) ->
|
compat_windows(Fun, Args) ->
|
||||||
try
|
try
|
||||||
case is_windows() of
|
case emqx_os_mon:is_os_check_supported() of
|
||||||
true -> 0.0;
|
false -> 0.0;
|
||||||
false when Args =:= [] -> Fun();
|
true when Args =:= [] -> Fun();
|
||||||
false -> Fun(Args)
|
true -> Fun(Args)
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
_:_ -> 0.0
|
_:_ -> 0.0
|
||||||
end.
|
end.
|
||||||
|
|
||||||
is_windows() ->
|
|
||||||
os:type() =:= {win32, nt}.
|
|
||||||
|
|
||||||
load(Avg) ->
|
load(Avg) ->
|
||||||
floor((Avg / 256) * 100) / 100.
|
floor((Avg / 256) * 100) / 100.
|
||||||
|
|
||||||
|
|
|
@ -185,17 +185,28 @@ node_info(Nodes) ->
|
||||||
stopped_node_info(Node) ->
|
stopped_node_info(Node) ->
|
||||||
{Node, #{node => Node, node_status => 'stopped', role => core}}.
|
{Node, #{node => Node, node_status => 'stopped', role => core}}.
|
||||||
|
|
||||||
|
%% Hide cpu stats if os_check is not supported.
|
||||||
vm_stats() ->
|
vm_stats() ->
|
||||||
Idle = vm_stats('cpu.idle'),
|
|
||||||
{MemUsedRatio, MemTotal} = get_sys_memory(),
|
{MemUsedRatio, MemTotal} = get_sys_memory(),
|
||||||
|
cpu_stats() ++
|
||||||
[
|
[
|
||||||
{run_queue, vm_stats('run.queue')},
|
{run_queue, vm_stats('run.queue')},
|
||||||
{cpu_idle, Idle},
|
|
||||||
{cpu_use, 100 - Idle},
|
|
||||||
{total_memory, MemTotal},
|
{total_memory, MemTotal},
|
||||||
{used_memory, erlang:round(MemTotal * MemUsedRatio)}
|
{used_memory, erlang:round(MemTotal * MemUsedRatio)}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
cpu_stats() ->
|
||||||
|
case emqx_os_mon:is_os_check_supported() of
|
||||||
|
false ->
|
||||||
|
[];
|
||||||
|
true ->
|
||||||
|
Idle = vm_stats('cpu.idle'),
|
||||||
|
[
|
||||||
|
{cpu_idle, Idle},
|
||||||
|
{cpu_use, 100 - Idle}
|
||||||
|
]
|
||||||
|
end.
|
||||||
|
|
||||||
vm_stats('cpu.idle') ->
|
vm_stats('cpu.idle') ->
|
||||||
case emqx_vm:cpu_util([detailed]) of
|
case emqx_vm:cpu_util([detailed]) of
|
||||||
{_Num, _Use, List, _} when is_list(List) -> proplists:get_value(idle, List, 0);
|
{_Num, _Use, List, _} when is_list(List) -> proplists:get_value(idle, List, 0);
|
||||||
|
|
Loading…
Reference in New Issue