mirror of https://github.com/elunez/eladmin
[Fix] 磁盘使用率计算bug, 机器挂载多盘时只计算了最后一块盘
parent
41cd93053a
commit
cfeb248067
|
@ -73,15 +73,18 @@ public class MonitorServiceImpl implements MonitorService {
|
||||||
Map<String,Object> diskInfo = new LinkedHashMap<>();
|
Map<String,Object> diskInfo = new LinkedHashMap<>();
|
||||||
FileSystem fileSystem = os.getFileSystem();
|
FileSystem fileSystem = os.getFileSystem();
|
||||||
List<OSFileStore> fsArray = fileSystem.getFileStores();
|
List<OSFileStore> fsArray = fileSystem.getFileStores();
|
||||||
|
long available = 0L;
|
||||||
|
long total = 0L;
|
||||||
|
long used = 0L;
|
||||||
for (OSFileStore fs : fsArray) {
|
for (OSFileStore fs : fsArray) {
|
||||||
long available = fs.getUsableSpace();
|
available += fs.getUsableSpace();
|
||||||
long total = fs.getTotalSpace();
|
total += fs.getTotalSpace();
|
||||||
long used = total - available;
|
}
|
||||||
|
used += total - available;
|
||||||
diskInfo.put("total", total > 0 ? FileUtil.getSize(total) : "?");
|
diskInfo.put("total", total > 0 ? FileUtil.getSize(total) : "?");
|
||||||
diskInfo.put("available", FileUtil.getSize(available));
|
diskInfo.put("available", FileUtil.getSize(available));
|
||||||
diskInfo.put("used", FileUtil.getSize(used));
|
diskInfo.put("used", FileUtil.getSize(used));
|
||||||
diskInfo.put("usageRate", df.format(used/(double)fs.getTotalSpace() * 100));
|
diskInfo.put("usageRate", df.format(used/(double)total * 100));
|
||||||
}
|
|
||||||
return diskInfo;
|
return diskInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue