xdn-code opened a new pull request, #4421: URL: https://github.com/apache/hertzbeat/pull/4421
## What's changed? Linux-family CPU usage was computed as `usage=100-idle`, with `idle` coming from `vmstat 1 2`. vmstat only prints whole percentages and the 1-second sample jumps between integer values, which matches the charts in #3533. This follows the root-cause analysis in the issue: - Sample `/proc/stat` twice (1s apart) and compute idle as a 2-decimal percentage from the jiffy delta - Keep `usage=100-idle` so the existing metric mapping stays the same - Apply the same template change to linux, centos, ubuntu, debian, redhat, rockylinux, almalinux, euleros, opensuse, coreos, and linux_script - Use `kern.cp_time` on FreeBSD, which has no `/proc/stat` - Parse MCP bash-server idle as `f64` so decimal values are not truncated to 0 ## Checklist - [x] I have read the [Contributing Guide](https://hertzbeat.apache.org/docs/community/code_style_and_quality_guide) - [x] I have written the necessary doc or comment. - [x] I have added the necessary unit tests and all cases have passed. ## Add or update API - [ ] I have added the necessary [e2e tests](https://github.com/apache/hertzbeat/tree/master/e2e) and all cases have passed. ## Test plan - [x] `MetricsCollectTest.calculateFieldsKeepsDecimalCpuUsage` (`usage=100-98.47` → `1.53`) - [x] Simulated `/proc/stat` awk delta math locally Fixes #3533 Made with [Cursor](https://cursor.com) -- 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]
