perf: replace gopsutil sampling with cached metrics and optimize system info retrieval #11079
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it?
#11077 #11078
Summary of your change
优化时间: 100ms -> 1 μs 左右

Please indicate you've done the following:
copilot summary
This pull request refactors system resource monitoring in the agent by introducing a new
psutilutility package that provides cached and optimized access to CPU, disk, and host information. The changes replace direct usage ofgopsutilfunctions throughout the service layer with calls to the newpsutilabstractions, improving performance and consistency in resource data retrieval. Key updates include changes to CPU and disk usage calculations, host info loading, and dashboard data aggregation.System resource access refactoring:
agent/utils/psutilpackage, which provides thread-safe, cached access to CPU, disk, and host information through global state objects (CPU,CPUInfo,DISK,HOST). [1] [2] [3] [4]gopsutilfunctions inagent/app/service/dashboard.go,agent/app/service/alert_helper.go, andagent/app/service/monitor.goto use the newpsutilmethods for CPU core counts, CPU usage, disk usage, and host info. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Dashboard and monitoring logic improvements:
Other enhancements:
cmp.Ormethod for environment variable selection.