[Fix] 磁盘使用率计算bug, 机器挂载多盘时只计算了最后一块盘

pull/530/head
fakeyanss 2020-11-22 17:08:34 +08:00
parent 41cd93053a
commit cfeb248067
1 changed files with 11 additions and 8 deletions

View File

@ -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;
} }