You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "xBis7 (via GitHub)" <gi...@apache.org> on 2024/01/05 23:07:07 UTC

Re: [PR] HDDS-9988. SCM UI shows storage usage percentage [ozone]

xBis7 commented on code in PR #5882:
URL: https://github.com/apache/ozone/pull/5882#discussion_r1443507613


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1109,6 +1112,23 @@ public Map<String, Map<String, String>> getNodeStatusInfo() {
         map.put(httpsPort.getName().toString(),
                   httpsPort.getValue().toString());
       }
+      List<StorageReportProto> storageReports = dni.getStorageReports();
+      if (storageReports != null && !storageReports.isEmpty()) {
+        long capacity = 0;
+        long scmUsed = 0;
+        for (StorageReportProto storageReport : storageReports) {
+          capacity = capacity + storageReport.getCapacity();
+          scmUsed = scmUsed + storageReport.getScmUsed();
+        }
+        double percent = (double) scmUsed / capacity;
+        percent = percent > 100.0 ? 100.0 : percent;
+        DecimalFormat decimalFormat = new DecimalFormat("#0.0000");
+        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
+        double usedPec = Double.valueOf(decimalFormat.format(percent)) * 100;
+        map.put(usedPercent, usedPec + "%");
+      } else {
+        map.put(usedPercent, "0%");

Review Comment:
   @jianghuazhu Can you move the logic for calculating the percentage to a method so that it can be easily tested? Also if you can add a unit test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org