The CPU Watcher is a continuous polling loop that reads overall CPU usage percent from the operating system and prints it to the terminal on every cycle. It is implemented in theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/stratosphere-ve/core/llms.txt
Use this file to discover all available pages before exploring further.
cpuwatcher package and uses the gopsutil library to gather CPU statistics without platform-specific system calls.
What it does
On each iteration,WatchCPU() calls cpu.Percent() with the configured polling duration and false for per-CPU reporting, which returns a single aggregate usage value across all cores. The result is printed alongside the current polling rate, then the loop immediately begins the next sample.
Output format:
Source code
cpuwatcher/cpuwatcher.go
CLI usage
Set the polling rate (optional)
Select option 1 from the menu. This sets the CPU polling rate to 2 seconds and immediately starts the watcher.
Example output
Polling rate
The default polling rate is 1 second. Selecting CLI option1 calls CPUSetPollingRate(2), which sets the rate to 2 seconds before starting the loop.
You can inspect the cpuPollingRate variable or call CPUSetPollingRate() directly in code to set any rate you need.
Functions
| Function | Description |
|---|---|
WatchCPU() | Starts the infinite CPU polling loop. Prints usage percent and polling rate on each cycle. |
CPUSetPollingRate(rate float64) | Sets the polling interval in seconds. Accepts a float64 value (e.g. 2.0 for 2 seconds). |