Increase CPU sampling interval for accurate readings
Changed from 100ms to 1 second sampling interval in gopsutil cpu.Percent() call. Shorter intervals can give inaccurate readings due to timing issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -77,8 +77,9 @@ func (c *Collector) Collect() SystemStats {
|
||||
}
|
||||
|
||||
func (c *Collector) collectCPU(stats *SystemStats) {
|
||||
// Get CPU usage percentage (this blocks for ~100ms to sample)
|
||||
if cpuPercent, err := cpu.Percent(100*time.Millisecond, false); err == nil && len(cpuPercent) > 0 {
|
||||
// Get CPU usage percentage (blocks for 1 second to get accurate sample)
|
||||
// Shorter intervals can give inaccurate readings
|
||||
if cpuPercent, err := cpu.Percent(time.Second, false); err == nil && len(cpuPercent) > 0 {
|
||||
stats.CPU.UsagePercent = cpuPercent[0]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user