dill21yu commented on code in PR #17174:
URL: 
https://github.com/apache/dolphinscheduler/pull/17174#discussion_r2086031895


##########
dolphinscheduler-meter/src/main/java/org/apache/dolphinscheduler/meter/metrics/DefaultMetricsProvider.java:
##########
@@ -59,8 +60,19 @@ public SystemMetrics getSystemMetrics() {
             lastProcessCpuUsage = processCpuUsage;
         }
 
-        double jvmMemoryUsed = 
meterRegistry.get("jvm.memory.used").meter().measure().iterator().next().getValue();
-        double jvmMemoryMax = 
meterRegistry.get("jvm.memory.max").meter().measure().iterator().next().getValue();
+        // Calculate JVM memory usage and maximum values
+        double jvmHeapUsed = calculateTotalMemory(meterRegistry, "heap", 
"jvm.memory.used");
+        double jvmNonHeapUsed = calculateTotalMemory(meterRegistry, "nonheap", 
"jvm.memory.used");
+
+        double jvmHeapMax = calculateTotalMemory(meterRegistry, "heap", 
"jvm.memory.max");
+        double jvmNonHeapMax = calculateTotalMemory(meterRegistry, "nonheap", 
"jvm.memory.max");
+
+        // Calculate totals
+        double jvmMemoryUsed = jvmHeapUsed + jvmNonHeapUsed;
+        double jvmMemoryMax = jvmHeapMax + jvmNonHeapMax;
+
+        // Ensure jvmMemoryMax is not zero
+        double jvmMemoryUsedPercentage = (jvmMemoryMax > 0) ? (jvmMemoryUsed / 
jvmMemoryMax) : 0.0;

Review Comment:
   
   The initial value of jvmMemoryMax is 0. It accumulates the maximum memory 
values and should not be 0 under normal circumstances. However, the Sonar scan 
reports an issue to avoid a potential division by zero error:"Make sure 
"jvmMemoryMax" can't be zero before doing this division."



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to