|
8 | 8 | "sync" |
9 | 9 | "time" |
10 | 10 |
|
| 11 | + // gopsutil provides cross-platform system and process utilities. |
| 12 | + // It supports linux/amd64 and darwin/amd64 (the target platforms for this codebase), |
| 13 | + // as well as Windows, FreeBSD, OpenBSD, and Solaris. |
11 | 14 | "github.com/shirou/gopsutil/cpu" |
12 | 15 | "github.com/shirou/gopsutil/mem" |
13 | 16 | ) |
@@ -424,7 +427,7 @@ func (pm *PerformanceMetrics) SetGauge(name string, value float64) { |
424 | 427 | // observeSystemMetrics periodically collects and updates system metrics |
425 | 428 | // including CPU utilization, memory usage, and goroutine count. |
426 | 429 | func (pm *PerformanceMetrics) observeSystemMetrics(ctx context.Context) { |
427 | | - ticker := time.NewTicker(10 * time.Second) // Update every 10 seconds |
| 430 | + ticker := time.NewTicker(60 * time.Second) // Update every 10 seconds |
428 | 431 | defer ticker.Stop() |
429 | 432 |
|
430 | 433 | var lastMemStats runtime.MemStats |
@@ -520,6 +523,10 @@ func (pm *PerformanceMetrics) calculateCPUUtilizationHeuristic( |
520 | 523 | // including CPU load, RAM utilization, and swapfile utilization. |
521 | 524 | func (pm *PerformanceMetrics) updateMachineStats() { |
522 | 525 | // Get CPU load percentage (1-second average) |
| 526 | + // NOTE: cpu.Percent blocks for the specified duration (1 second) to sample |
| 527 | + // CPU usage over that interval. This blocking behavior is intentional and |
| 528 | + // necessary to obtain an accurate CPU utilization measurement. The function |
| 529 | + // will not return until the 1-second sampling period completes. |
523 | 530 | cpuPercent, err := cpu.Percent(time.Second, false) |
524 | 531 | if err == nil && len(cpuPercent) > 0 { |
525 | 532 | pm.SetGauge(MetricCPULoadPercent, cpuPercent[0]) |
|
0 commit comments