[Feature] Add detailed CPU metrics (User, System, IOWait, Steal) with per-core monitoring (#1356)

* Add user, system io wait

* add per cpu core

* add total
This commit is contained in:
Sven van Ginkel
2025-10-31 22:11:22 +01:00
committed by GitHub
parent 85ac2e5e9a
commit fe30f99695
7 changed files with 303 additions and 7 deletions

View File

@@ -83,12 +83,21 @@ func (a *Agent) getSystemStats(cacheTimeMs uint16) system.Stats {
systemStats.Battery[1] = batteryState
}
// cpu percent
cpuPercent, err := getCpuPercent(cacheTimeMs)
// cpu metrics
cpuMetrics, err := getCpuMetrics(cacheTimeMs)
if err == nil {
systemStats.Cpu = twoDecimals(cpuPercent)
systemStats.Cpu = twoDecimals(cpuMetrics.Total)
systemStats.CpuUser = twoDecimals(cpuMetrics.User)
systemStats.CpuSystem = twoDecimals(cpuMetrics.System)
systemStats.CpuIowait = twoDecimals(cpuMetrics.Iowait)
systemStats.CpuSteal = twoDecimals(cpuMetrics.Steal)
} else {
slog.Error("Error getting cpu percent", "err", err)
slog.Error("Error getting cpu metrics", "err", err)
}
// per-core cpu metrics
if perCoreCpuMetrics, err := getPerCoreCpuMetrics(cacheTimeMs); err == nil && len(perCoreCpuMetrics) > 0 {
systemStats.CpuCores = perCoreCpuMetrics
}
// load average