From 9591cf3e53c307d42bc82b866f7b096f19120456 Mon Sep 17 00:00:00 2001 From: ZhengJie <201507802@qq.com> Date: Mon, 16 Nov 2020 19:21:28 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2.6)?= =?UTF-8?q?=EF=BC=9A=E6=9C=8D=E5=8A=A1=E7=9B=91=E6=8E=A7=E5=85=BC=E5=AE=B9?= =?UTF-8?q?Mac=20Os=20Big=20Sur=EF=BC=8C=E4=BA=A4=E6=8D=A2=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-system/pom.xml | 4 ++-- .../service/impl/MonitorServiceImpl.java | 24 ++++++++++++------- pom.xml | 1 + 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index bca08a7a..366ac367 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -15,7 +15,7 @@ 0.11.1 - 5.5.0 + 5.6.0 @@ -84,7 +84,7 @@ com.github.oshi oshi-core - 5.0.1 + 5.3.6 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java index 87f9bc20..99aaef88 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java @@ -50,7 +50,6 @@ public class MonitorServiceImpl implements MonitorService { HardwareAbstractionLayer hal = si.getHardware(); // 系统信息 resultMap.put("sys", getSystemInfo(os)); - // cpu 信息 resultMap.put("cpu", getCpuInfo(hal.getProcessor())); // 内存信息 @@ -75,9 +74,11 @@ public class MonitorServiceImpl implements MonitorService { FileSystem fileSystem = os.getFileSystem(); List fsArray = fileSystem.getFileStores(); for (OSFileStore fs : fsArray){ - diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtil.getSize(fs.getTotalSpace()) : "?"); - long used = fs.getTotalSpace() - fs.getUsableSpace(); - diskInfo.put("available", FileUtil.getSize(fs.getUsableSpace())); + long available = fs.getUsableSpace(); + long total = fs.getTotalSpace(); + long used = total - available; + diskInfo.put("total", total > 0 ? FileUtil.getSize(total) : "?"); + diskInfo.put("available", FileUtil.getSize(available)); diskInfo.put("used", FileUtil.getSize(used)); diskInfo.put("usageRate", df.format(used/(double)fs.getTotalSpace() * 100)); } @@ -91,10 +92,17 @@ public class MonitorServiceImpl implements MonitorService { */ private Map getSwapInfo(GlobalMemory memory) { Map swapInfo = new LinkedHashMap<>(); - swapInfo.put("total", FormatUtil.formatBytes(memory.getVirtualMemory().getSwapTotal())); - swapInfo.put("used", FormatUtil.formatBytes(memory.getVirtualMemory().getSwapUsed())); - swapInfo.put("available", FormatUtil.formatBytes(memory.getVirtualMemory().getSwapTotal() - memory.getVirtualMemory().getSwapUsed())); - swapInfo.put("usageRate", df.format(memory.getVirtualMemory().getSwapUsed()/(double)memory.getVirtualMemory().getSwapTotal() * 100)); + VirtualMemory virtualMemory = memory.getVirtualMemory(); + long total = virtualMemory.getSwapTotal(); + long used = virtualMemory.getSwapUsed(); + swapInfo.put("total", FormatUtil.formatBytes(total)); + swapInfo.put("used", FormatUtil.formatBytes(used)); + swapInfo.put("available", FormatUtil.formatBytes(total - used)); + if(used == 0){ + swapInfo.put("usageRate", 0); + } else { + swapInfo.put("usageRate", df.format(used/(double)total * 100)); + } return swapInfo; } diff --git a/pom.xml b/pom.xml index 049c02b3..b8fe4a46 100644 --- a/pom.xml +++ b/pom.xml @@ -144,6 +144,7 @@ ip2region 1.7.2 + org.projectlombok