github-actions[bot] commented on code in PR #60777:
URL: https://github.com/apache/doris/pull/60777#discussion_r2900482620
##########
fe/fe-core/src/main/java/org/apache/doris/metric/SystemMetrics.java:
##########
@@ -145,4 +204,139 @@ private void updateMemoryMetrics() {
}
}
+ private void updateCpuMetrics() {
+ String procFile = "/proc/stat";
+ if (FeConstants.runningUnitTest) {
+ procFile =
getClass().getClassLoader().getResource("data/stat_normal").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 = line.split("\\s+");
+ if (parts.length >= 11) {
+ // Full format with guest/guest_nice (kernel >= 2.6.24
with guest, >= 2.6.33 with guest_nice)
+ cpuUser = Long.parseLong(parts[1]);
+ cpuNice = Long.parseLong(parts[2]);
+ cpuSystem = Long.parseLong(parts[3]);
+ cpuIdle = Long.parseLong(parts[4]);
+ cpuIowait = Long.parseLong(parts[5]);
+ cpuIrq = Long.parseLong(parts[6]);
+ cpuSoftirq = Long.parseLong(parts[7]);
+ cpuSteal = Long.parseLong(parts[8]);
+ cpuGuest = Long.parseLong(parts[9]);
+ cpuGuestNice = Long.parseLong(parts[10]);
+ } else if (parts.length >= 9) {
+ // Format with steal but without guest/guest_nice
(kernel >= 2.6.11)
+ cpuUser = Long.parseLong(parts[1]);
+ cpuNice = Long.parseLong(parts[2]);
+ cpuSystem = Long.parseLong(parts[3]);
+ cpuIdle = Long.parseLong(parts[4]);
+ cpuIowait = Long.parseLong(parts[5]);
+ cpuIrq = Long.parseLong(parts[6]);
+ cpuSoftirq = Long.parseLong(parts[7]);
+ cpuSteal = Long.parseLong(parts[8]);
+ cpuGuest = 0;
+ cpuGuestNice = 0;
+ } else if (parts.length >= 8) {
+ // Older format without steal (kernel < 2.6.11)
+ cpuUser = Long.parseLong(parts[1]);
+ cpuNice = Long.parseLong(parts[2]);
+ cpuSystem = Long.parseLong(parts[3]);
+ cpuIdle = Long.parseLong(parts[4]);
+ cpuIowait = Long.parseLong(parts[5]);
+ cpuIrq = Long.parseLong(parts[6]);
+ cpuSoftirq = Long.parseLong(parts[7]);
+ cpuSteal = 0;
+ cpuGuest = 0;
+ cpuGuestNice = 0;
+ }
+ } else if (line.startsWith("ctxt ")) {
+ String[] parts = line.split("\\s+");
+ if (parts.length >= 2) {
+ ctxt = Long.parseLong(parts[1]);
+ }
+ } else if (line.startsWith("procs_running ")) {
+ String[] parts = line.split("\\s+");
+ if (parts.length >= 2) {
+ procsRunning = Long.parseLong(parts[1]);
+ }
+ } else if (line.startsWith("procs_blocked ")) {
+ String[] parts = line.split("\\s+");
+ if (parts.length >= 2) {
+ procsBlocked = Long.parseLong(parts[1]);
+ }
+ }
+ }
+
+ // Validate that CPU line was found
+ if (!cpuLineFound) {
+ LOG.warn("failed to get /proc/stat: cpu line not found");
Review Comment:
Bug: The `processes` line from `/proc/stat` is never parsed. The code parses
`ctxt`, `procs_running`, and `procs_blocked`, but is missing an `else if
(line.startsWith("processes "))` block. As a result, the `processes` field
always stays at `0`, and the `processesRate` (exposed as `process_forks_rate`
metric) will always report `0.0`.
The test data file `stat_normal` contains `processes 5000000` on line 9, but
this value is never read.
Suggested fix — add a block like:
```java
} else if (line.startsWith("processes ")) {
String[] parts = line.split("\\s+");
if (parts.length >= 2) {
processes = Long.parseLong(parts[1]);
}
}
```
between the `ctxt` and `procs_running` parsing blocks (or anywhere in the
`while` loop).
--
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]