From 53c55f7dc55f4b815e0918918a04eb29712b1697 Mon Sep 17 00:00:00 2001 From: aaron ai Date: Sun, 12 Sep 2021 16:50:48 +0800 Subject: [PATCH] [ISSUE #3245] Use df algorithm to calculate the disk used ratio --- .../java/org/apache/rocketmq/common/UtilAll.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java index 776c991c..6318be07 100644 --- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java @@ -218,10 +218,15 @@ public class UtilAll { long totalSpace = file.getTotalSpace(); if (totalSpace > 0) { - long freeSpace = file.getFreeSpace(); - long usedSpace = totalSpace - freeSpace; - - return usedSpace / (double) totalSpace; + long usedSpace = totalSpace - file.getFreeSpace(); + long usableSpace = file.getUsableSpace(); + long entireSpace = usedSpace + usableSpace; + long roundNum = 0; + if (usedSpace * 100 % entireSpace != 0) { + roundNum = 1; + } + long result = usedSpace * 100 / entireSpace + roundNum; + return result / 100.0; } } catch (Exception e) { log.error("Error when measuring disk space usage, got exception: :", e); -- GitLab