Lightweight server monitoring with historical data, docker stats, and alerts.
feat(agent): add IRQ, SoftIRQ and Nice to CPU breakdown (#2647)
Sven van Ginkelb5357343550c
diff --git a/agent/cpu.go b/agent/cpu.goindex 9db50b7f0..a433a37a1 100644--- a/agent/cpu.go+++ b/agent/cpu.go@@ -24,12 +24,15 @@ func init() {// CpuMetrics contains detailed CPU usage breakdowntype CpuMetrics struct {- Total float64- User float64- System float64- Iowait float64- Steal float64- Idle float64+ Total float64+ User float64+ System float64+ Iowait float64+ Steal float64+ Idle float64+ Irq float64+ Softirq float64+ Nice float64// fromCgroup is set when Total comes from cgroup accounting rather than// /proc/stat, so per-core /proc/stat usage would not match it.fromCgroup bool@@ -73,12 +76,15 @@ func cpuMetricsFromTimes(cacheTimeMs uint16, current cpu.TimesStat) CpuMetrics {}metrics := CpuMetrics{- Total: calculateBusy(t1, t2),- User: clampPercent((t2.User - t1.User) / totalDelta * 100),- System: clampPercent((t2.System - t1.System) / totalDelta * 100),- Iowait: clampPercent((t2.Iowait - t1.Iowait) / totalDelta * 100),- Steal: clampPercent((t2.Steal - t1.Steal) / totalDelta * 100),- Idle: clampPercent((t2.Idle - t1.Idle) / totalDelta * 100),+ Total: calculateBusy(t1, t2),+ User: clampPercent((t2.User - t1.User) / totalDelta * 100),+ System: clampPercent((t2.System - t1.System) / totalDelta * 100),+ Iowait: clampPercent((t2.Iowait - t1.Iowait) / totalDelta * 100),+ Steal: clampPercent((t2.Steal - t1.Steal) / totalDelta * 100),+ Idle: clampPercent((t2.Idle - t1.Idle) / totalDelta * 100),+ Irq: clampPercent((t2.Irq - t1.Irq) / totalDelta * 100),+ Softirq: clampPercent((t2.Softirq - t1.Softirq) / totalDelta * 100),+ Nice: clampPercent((t2.Nice - t1.Nice) / totalDelta * 100),}return metricsdiff --git a/agent/system.go b/agent/system.goindex 793da4647..084ad37af 100644--- a/agent/system.go+++ b/agent/system.go@@ -171,6 +171,9 @@ func (a *Agent) getSystemStats(cacheTimeMs uint16) system.Stats {utils.TwoDecimals(cpuMetrics.Iowait),utils.TwoDecimals(cpuMetrics.Steal),utils.TwoDecimals(cpuMetrics.Idle),+ utils.TwoDecimals(cpuMetrics.Irq),+ utils.TwoDecimals(cpuMetrics.Softirq),+ utils.TwoDecimals(cpuMetrics.Nice),}} else {slog.Error("Error getting cpu metrics", "err", err)diff --git a/internal/entities/system/system.go b/internal/entities/system/system.goindex f6ab3620c..b6b6168f0 100644--- a/internal/entities/system/system.go+++ b/internal/entities/system/system.go@@ -50,7 +50,7 @@ type Stats struct {NetworkInterfaces map[string][4]uint64 `json:"ni,omitempty" cbor:"31,keyasint,omitempty"` // [upload bytes, download bytes, total upload, total download]DiskIO [2]uint64 `json:"dio,omitzero" cbor:"32,keyasint,omitzero"` // [read bytes, write bytes]MaxDiskIO [2]uint64 `json:"diom,omitzero" cbor:"-"` // [max read bytes, max write bytes]- CpuBreakdown []float64 `json:"cpub,omitempty" cbor:"33,keyasint,omitempty"` // [user, system, iowait, steal, idle]+ CpuBreakdown []float64 `json:"cpub,omitempty" cbor:"33,keyasint,omitempty"` // [user, system, iowait, steal, idle, irq, softirq, nice]CpuCoresUsage Uint8Slice `json:"cpus,omitempty" cbor:"34,keyasint,omitempty"` // per-core busy usage [CPU0..]DiskIoStats [6]float64 `json:"dios,omitzero" cbor:"35,keyasint,omitzero"` // [read time %, write time %, io utilization %, r_await ms, w_await ms, weighted io %]MaxDiskIoStats [6]float64 `json:"diosm,omitzero" cbor:"-"` // max values for DiskIoStatsdiff --git a/internal/site/src/components/routes/system/cpu-sheet.tsx b/internal/site/src/components/routes/system/cpu-sheet.tsxindex 080d70009..e701ac1fa 100644--- a/internal/site/src/components/routes/system/cpu-sheet.tsx+++ b/internal/site/src/components/routes/system/cpu-sheet.tsx@@ -91,11 +91,32 @@ export default memo(function CpuCoresSheet({opacity: 0.35,stackId: "a",},+ {+ label: "IRQ",+ dataKey: ({ stats }: SystemStatsRecord) => stats?.cpub?.[5],+ color: "hsl(195, 70%, 50%)",+ opacity: 0.35,+ stackId: "a",+ },+ {+ label: t`SoftIRQ`,+ dataKey: ({ stats }: SystemStatsRecord) => stats?.cpub?.[6],+ color: "hsl(50, 80%, 52%)",+ opacity: 0.35,+ stackId: "a",+ },+ {+ label: t`Nice`,+ dataKey: ({ stats }: SystemStatsRecord) => stats?.cpub?.[7],+ color: "hsl(300, 60%, 55%)",+ opacity: 0.35,+ stackId: "a",+ },{label: t`Other`,dataKey: ({ stats }: SystemStatsRecord) => {const total = stats?.cpub?.reduce((acc, curr) => acc + curr, 0) ?? 0- return total > 0 ? 100 - total : null+ return total > 0 ? Math.max(0, 100 - total) : null},color: `hsl(80, 65%, 52%)`,opacity: 0.35,diff --git a/internal/site/src/types.d.ts b/internal/site/src/types.d.tsindex fa44adcb9..92b920c9e 100644--- a/internal/site/src/types.d.ts+++ b/internal/site/src/types.d.ts@@ -98,7 +98,7 @@ export interface SystemStats {cpu: number/** peak cpu */cpum?: number- /** cpu breakdown [user, system, iowait, steal, idle] (0-100 integers) */+ /** cpu breakdown [user, system, iowait, steal, idle, irq, softirq, nice] (0-100 integers) */cpub?: number[]/** per-core cpu usage [CPU0..] (0-100 integers) */cpus?: number[]