Sfoglia il codice sorgente

!439 修复在Docker中无法获取CPU占用率报错的问题和修复前端获取缓存出现报错的情况
Merge pull request !439 from 新无止竞/next

zuohuaijun 3 anni fa
parent
commit
f799e8e9da

+ 2 - 2
Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs

@@ -178,9 +178,9 @@ public class SysCacheService : IDynamicApiController, ISingleton
     /// <param name="cacheKey"></param>
     /// <returns></returns>
     [HttpGet("/sysCache/detail")]
-    public string CacheDetail(string cacheKey)
+    public dynamic CacheDetail(string cacheKey)
     {
-        return _cache.Get<string>(cacheKey);
+        return _cache.Get<dynamic>(cacheKey);
     }
 
     ///// <summary>

+ 3 - 11
Admin.NET/Admin.NET.Core/Util/ServerUtil.cs

@@ -64,15 +64,6 @@ public class ServerUtil
     {
         if (IsUnix())
         {
-            //var output = ShellUtil.Bash("free -m");
-            //var lines = output.Split("\n");
-            //var memory = lines[1].Split(" ", StringSplitOptions.RemoveEmptyEntries);
-            //return new
-            //{
-            //    Total = double.Parse(memory[1]),
-            //    Used = double.Parse(memory[2]),
-            //    Free = double.Parse(memory[3])
-            //};
             var output = ShellUtil.Bash("cat /proc/meminfo");
             var lines = output.Split("\n");
             return new
@@ -100,6 +91,7 @@ public class ServerUtil
         }
     }
 
+
     /// <summary>
     /// CPU信息
     /// </summary>
@@ -110,14 +102,14 @@ public class ServerUtil
         if (IsUnix())
         {
             var output = ShellUtil.Bash("top -b -n1 | grep \"Cpu(s)\" | awk '{print $2 + $4}'");
-            cpuRate = output.Trim();
+            cpuRate = output.Trim() ;
         }
         else
         {
             var output = ShellUtil.Cmd("wmic", "cpu get LoadPercentage");
             cpuRate = output.Replace("LoadPercentage", string.Empty).Trim();
         }
-        return cpuRate;
+        return cpuRate == "" ? "0" : cpuRate;
     }
 
     /// <summary>