فهرست منبع

fix: hide cpu_status if os_check is not supported

zhongwencool 2 سال پیش
والد
کامیت
8b23ee86b3
2فایلهای تغییر یافته به همراه23 افزوده شده و 15 حذف شده
  1. 4 7
      apps/emqx/src/emqx_vm.erl
  2. 19 8
      apps/emqx_management/src/emqx_mgmt.erl

+ 4 - 7
apps/emqx/src/emqx_vm.erl

@@ -390,18 +390,15 @@ compat_windows(Fun) ->
 
 compat_windows(Fun, Args) ->
     try
-        case is_windows() of
-            true -> 0.0;
-            false when Args =:= [] -> Fun();
-            false -> Fun(Args)
+        case emqx_os_mon:is_os_check_supported() of
+            false -> 0.0;
+            true when Args =:= [] -> Fun();
+            true -> Fun(Args)
         end
     catch
         _:_ -> 0.0
     end.
 
-is_windows() ->
-    os:type() =:= {win32, nt}.
-
 load(Avg) ->
     floor((Avg / 256) * 100) / 100.
 

+ 19 - 8
apps/emqx_management/src/emqx_mgmt.erl

@@ -185,16 +185,27 @@ node_info(Nodes) ->
 stopped_node_info(Node) ->
     {Node, #{node => Node, node_status => 'stopped', role => core}}.
 
+%% Hide cpu stats if os_check is not supported.
 vm_stats() ->
-    Idle = vm_stats('cpu.idle'),
     {MemUsedRatio, MemTotal} = get_sys_memory(),
-    [
-        {run_queue, vm_stats('run.queue')},
-        {cpu_idle, Idle},
-        {cpu_use, 100 - Idle},
-        {total_memory, MemTotal},
-        {used_memory, erlang:round(MemTotal * MemUsedRatio)}
-    ].
+    cpu_stats() ++
+        [
+            {run_queue, vm_stats('run.queue')},
+            {total_memory, MemTotal},
+            {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') ->
     case emqx_vm:cpu_util([detailed]) of