Skip to content

Commit f151167

Browse files
committed
Merge branch 'master' into deploy
2 parents 2f0e566 + 9591cf3 commit f151167

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

eladmin-system/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<properties>
1616
<jjwt.version>0.11.1</jjwt.version>
1717
<!-- oshi监控需要指定jna版本, 问题详见 https://github.com/oshi/oshi/issues/1040 -->
18-
<jna.version>5.5.0</jna.version>
18+
<jna.version>5.6.0</jna.version>
1919
</properties>
2020

2121
<dependencies>
@@ -84,7 +84,7 @@
8484
<dependency>
8585
<groupId>com.github.oshi</groupId>
8686
<artifactId>oshi-core</artifactId>
87-
<version>5.0.1</version>
87+
<version>5.3.6</version>
8888
</dependency>
8989
</dependencies>
9090

eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public Map<String,Object> getServers(){
5050
HardwareAbstractionLayer hal = si.getHardware();
5151
// 系统信息
5252
resultMap.put("sys", getSystemInfo(os));
53-
5453
// cpu 信息
5554
resultMap.put("cpu", getCpuInfo(hal.getProcessor()));
5655
// 内存信息
@@ -75,9 +74,11 @@ private Map<String,Object> getDiskInfo(OperatingSystem os) {
7574
FileSystem fileSystem = os.getFileSystem();
7675
List<OSFileStore> fsArray = fileSystem.getFileStores();
7776
for (OSFileStore fs : fsArray){
78-
diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtil.getSize(fs.getTotalSpace()) : "?");
79-
long used = fs.getTotalSpace() - fs.getUsableSpace();
80-
diskInfo.put("available", FileUtil.getSize(fs.getUsableSpace()));
77+
long available = fs.getUsableSpace();
78+
long total = fs.getTotalSpace();
79+
long used = total - available;
80+
diskInfo.put("total", total > 0 ? FileUtil.getSize(total) : "?");
81+
diskInfo.put("available", FileUtil.getSize(available));
8182
diskInfo.put("used", FileUtil.getSize(used));
8283
diskInfo.put("usageRate", df.format(used/(double)fs.getTotalSpace() * 100));
8384
}
@@ -91,10 +92,17 @@ private Map<String,Object> getDiskInfo(OperatingSystem os) {
9192
*/
9293
private Map<String,Object> getSwapInfo(GlobalMemory memory) {
9394
Map<String,Object> swapInfo = new LinkedHashMap<>();
94-
swapInfo.put("total", FormatUtil.formatBytes(memory.getVirtualMemory().getSwapTotal()));
95-
swapInfo.put("used", FormatUtil.formatBytes(memory.getVirtualMemory().getSwapUsed()));
96-
swapInfo.put("available", FormatUtil.formatBytes(memory.getVirtualMemory().getSwapTotal() - memory.getVirtualMemory().getSwapUsed()));
97-
swapInfo.put("usageRate", df.format(memory.getVirtualMemory().getSwapUsed()/(double)memory.getVirtualMemory().getSwapTotal() * 100));
95+
VirtualMemory virtualMemory = memory.getVirtualMemory();
96+
long total = virtualMemory.getSwapTotal();
97+
long used = virtualMemory.getSwapUsed();
98+
swapInfo.put("total", FormatUtil.formatBytes(total));
99+
swapInfo.put("used", FormatUtil.formatBytes(used));
100+
swapInfo.put("available", FormatUtil.formatBytes(total - used));
101+
if(used == 0){
102+
swapInfo.put("usageRate", 0);
103+
} else {
104+
swapInfo.put("usageRate", df.format(used/(double)total * 100));
105+
}
98106
return swapInfo;
99107
}
100108

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<artifactId>ip2region</artifactId>
145145
<version>1.7.2</version>
146146
</dependency>
147+
147148
<!--lombok插件-->
148149
<dependency>
149150
<groupId>org.projectlombok</groupId>

0 commit comments

Comments
 (0)