sahildevgon commented on code in PR #60777:
URL: https://github.com/apache/doris/pull/60777#discussion_r2945857783


##########
fe/fe-core/src/main/java/org/apache/doris/metric/SystemMetrics.java:
##########
@@ -145,4 +209,140 @@ private void updateMemoryMetrics() {
         }
     }
 
+    private void updateCpuMetrics() {
+        String procFile = "/proc/stat";
+        if (FeConstants.runningUnitTest) {
+            procFile = 
getClass().getClassLoader().getResource(cpuStatTestFile).getFile();
+        }
+
+        try (FileReader fileReader = new FileReader(procFile);
+                BufferedReader br = new BufferedReader(fileReader)) {
+            String line;
+            boolean cpuLineFound = false;
+
+            // Store previous values for delta calculation
+            long prevTotal = prevCpuUser + prevCpuNice + prevCpuSystem + 
prevCpuIdle
+                    + prevCpuIowait + prevCpuIrq + prevCpuSoftirq + 
prevCpuSteal;
+
+            while ((line = br.readLine()) != null) {
+                if (line.startsWith("cpu ")) {  // Overall CPU stats (not 
per-core)
+                    cpuLineFound = true;
+                    String[] parts = WHITESPACE.split(line);

Review Comment:
   Added an else clause



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to