fix: hide cpu_status if os_check is not supported

This commit is contained in:
zhongwencool 2023-08-16 15:19:18 +08:00
parent b817e03c08
commit 8b23ee86b3
2 changed files with 23 additions and 15 deletions

View File

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

View File

@ -185,16 +185,27 @@ 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')}, [
{cpu_idle, Idle}, {run_queue, vm_stats('run.queue')},
{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