Documentation
¶
Index ¶
- Constants
- func ClassifyCPU(load5 float64, cores int, idlePct float64) string
- func ClassifyLoad(ratio, idlePct float64) string
- func ClassifyMemoryPressure(code int) string
- func FormatKB(kb int64) string
- func HeavyPaging(swapUsedMB, swapTotalMB, swapoutsGB, ramGB float64) bool
- func HighKernelTime(sysPct, userPct float64) bool
- func IsThermalAlert(state string) bool
- type AppUsage
- type BatteryMonitor
- type CPUMonitor
- type LightOptions
- type LightReading
- type MemoryMonitor
- type Monitor
- type NetworkMonitor
- type ProcInfo
- type ProcSummary
- type ProcessMonitor
- type SystemMonitor
Constants ¶
const ( PressureNormal = "Normal" PressureWarning = "Warning" PressureCritical = "Critical" PressureUnknown = "Unknown" )
Memory pressure levels, from kern.memorystatus_vm_pressure_level.
const ( LoadNormal = "Normal" LoadHigh = "Alta" LoadSaturated = "Saturada" // LoadWaiting is a high load while the CPU is mostly idle: the load average // also counts tasks blocked on memory or disk, so it does not mean the CPU // is the bottleneck. LoadWaiting = "Carga alta con CPU libre: procesos esperando memoria o disco" )
CPU load verdicts, from the 5-minute load average per core.
const ( NoteHeavyPaging = "Paginación intensa: el swap está casi lleno y se ha escrito mucho " + "a disco desde el arranque. Puede indicar falta de RAM para la carga actual." // PagingOK is the calm verdict: no symptom is not proof of health. PagingOK = "Sin señales de paginación intensa." NoteKernelTime = "Tiempo de kernel elevado: el sistema gasta más CPU que las apps. " + "Puede deberse a paginación o a agentes de seguridad." )
Cautious wording: the toolkit observes symptoms, it cannot know the cause.
const ( ThermalNormal = "Normal" ThermalThrottled = "Throttled" ThermalWarning = "Warning" ThermalUnknown = "Unknown" )
Thermal states emitted by the system monitor. Only Throttled and Warning are alerts; Normal and Unknown must never be painted or counted as one.
Variables ¶
This section is empty.
Functions ¶
func ClassifyCPU ¶ added in v1.8.0
ClassifyCPU classifies the 5-minute load average against the core count. The 5-minute window is used instead of the 1-minute one so a short burst does not read as a saturated machine. Unknown core count yields Normal.
func ClassifyLoad ¶ added in v1.9.0
ClassifyLoad classifies a load-per-core ratio together with the idle share: below 1 is Normal. From 1 up, a CPU that is more than half idle means the load is tasks waiting on memory or disk, not CPU work (LoadWaiting); only with little idle time is it Alta (1-2, both bounds inclusive) or Saturada (>2). A negative idlePct means "unknown" and keeps the load-only rule.
func ClassifyMemoryPressure ¶ added in v1.8.0
ClassifyMemoryPressure maps the kernel pressure code (1 Normal, 2 Warning, 4 Critical) to a label. Any other value, including 0 for a failed read, is Unknown: not knowing must not look like an alarm.
func HeavyPaging ¶ added in v1.8.0
HeavyPaging reports intense paging: swap used above 80% of its total AND cumulative swapouts above twice the physical RAM. Requiring both avoids flagging a Mac that merely keeps a large, mostly idle swap file.
func HighKernelTime ¶ added in v1.8.0
HighKernelTime reports elevated kernel time: sys above 40% and above user.
func IsThermalAlert ¶ added in v1.7.1
IsThermalAlert reports whether a thermal state deserves the user's attention. It is an allowlist on purpose: new or unrecognised states stay quiet.
Types ¶
type AppUsage ¶ added in v1.8.0
type AppUsage struct {
Name string `json:"name"`
MemMB float64 `json:"mem_mb"`
CPUPct float64 `json:"cpu_pct"`
Procs int `json:"procs"`
}
AppUsage is one application's aggregated footprint. It deliberately has no PID and no path: only a display name and magnitudes, so it is safe to show and to log.
type BatteryMonitor ¶
type BatteryMonitor struct{}
func (*BatteryMonitor) Display ¶
func (b *BatteryMonitor) Display() error
func (*BatteryMonitor) Name ¶
func (b *BatteryMonitor) Name() string
type CPUMonitor ¶ added in v1.8.0
type CPUMonitor struct{}
CPUMonitor is a read-only view of CPU time split, load and the busiest apps.
func (*CPUMonitor) Display ¶ added in v1.8.0
func (c *CPUMonitor) Display() error
Display prints the CPU view for the CLI.
func (*CPUMonitor) Name ¶ added in v1.8.0
func (c *CPUMonitor) Name() string
type LightOptions ¶ added in v1.12.0
type LightOptions struct {
Thermal bool // `pmset -g therm` (~20 ms of CPU; changes slowly)
Apps bool // one `ps` for the top apps (~40 ms of CPU, the costliest)
}
LightOptions picks the optional, costlier sources of a reading.
type LightReading ¶ added in v1.12.0
type LightReading struct {
Load1, Load5, Load15 float64
LoadOK bool
Cores int
UserPct, SysPct, IdlePct float64
CPUOK bool
MemUsedPct float64
MemOK bool
PressureCode int // 1 Normal, 2 Warning, 4 Critical, 0 unknown
SwapUsedMB, SwapTotalMB float64
SwapOK bool
// Cumulative swap traffic since boot, in bytes. The watch engine turns the
// difference between two readings into a rate.
SwapinBytes, SwapoutBytes int64
Thermal string // empty when not requested
// Name of the app that uses the most CPU and memory (aggregated over its
// processes; no PID, no path).
TopCPUApp, TopMemApp string
}
LightReading is one cheap reading of the machine for the watch mode. It only uses sysctl, vm_stat, iostat, ps and (optionally) pmset: never top or system_profiler. Every field degrades on its own: a failed source leaves its fields at zero and its *OK flag false, and the rest of the reading is kept.
func ReadLight ¶ added in v1.12.0
func ReadLight(opt LightOptions) LightReading
ReadLight takes one light reading. Callers ask for the optional sources only every few readings to keep the average cost low.
type MemoryMonitor ¶ added in v1.8.0
type MemoryMonitor struct{}
MemoryMonitor is a read-only view of RAM, pressure, swap and the biggest apps. It never signals or modifies any process.
func (*MemoryMonitor) Display ¶ added in v1.8.0
func (m *MemoryMonitor) Display() error
Display prints the memory view for the CLI, in the same style as the other monitors.
func (*MemoryMonitor) Name ¶ added in v1.8.0
func (m *MemoryMonitor) Name() string
func (*MemoryMonitor) Snapshot ¶ added in v1.8.0
func (m *MemoryMonitor) Snapshot() (map[string]any, error)
Snapshot collects memory figures. Every optional source degrades on its own (a failing sysctl only drops its keys); only a failing vm_stat is an error, because without it there is no memory picture at all.
type NetworkMonitor ¶
type NetworkMonitor struct{}
func (*NetworkMonitor) Display ¶
func (n *NetworkMonitor) Display() error
func (*NetworkMonitor) Name ¶
func (n *NetworkMonitor) Name() string
type ProcInfo ¶ added in v1.9.0
type ProcInfo struct {
PID int `json:"pid"`
CPU float64 `json:"cpu_pct"`
Mem float64 `json:"mem_pct"`
RSSKB int64 `json:"rss_kb"`
Name string `json:"name"`
}
ProcInfo is one process as the LOCAL views show it. The PID is meant for the user's own screen and CLI only: nothing that is serialized for a model or logged carries this type (the AI snapshot reads names and percentages only).
type ProcSummary ¶ added in v1.9.0
type ProcSummary struct {
Total int `json:"total"`
Running int `json:"running"`
Sleeping int `json:"sleeping"`
Stopped int `json:"stopped"`
Zombie int `json:"zombie"`
IOWait int `json:"io_wait"` // uninterruptible wait, usually disk/memory
}
ProcSummary counts processes by state. Threads are not counted: ps needs one extra full pass per thread to list them, which is not worth the cost here.
type ProcessMonitor ¶
type ProcessMonitor struct{}
ProcessMonitor is a read-only view of the busiest processes, their per-app totals and the process-state summary. It never signals a process.
func (*ProcessMonitor) Display ¶
func (p *ProcessMonitor) Display() error
Display prints the CLI tables with the top 10 of each list.
func (*ProcessMonitor) Name ¶
func (p *ProcessMonitor) Name() string
func (*ProcessMonitor) Snapshot ¶
func (p *ProcessMonitor) Snapshot() (map[string]any, error)
Snapshot returns the lists as typed values (not formatted text), so each front-end renders its own table.
top_cpu, top_memory []ProcInfo top 15 by %CPU / by RSS apps []AppUsage per-app totals, largest RAM first summary ProcSummary counts by state pressure_level string kernel memory pressure label memory_pressure string "free percentage" line, for the MCP tool
type SystemMonitor ¶
type SystemMonitor struct{ Light bool }
SystemMonitor reports hardware info and live CPU/memory/swap/thermal figures. Light drops the static hardware lookup; the TUI header uses it on every tick.
func (*SystemMonitor) Display ¶
func (s *SystemMonitor) Display() error
func (*SystemMonitor) Name ¶
func (s *SystemMonitor) Name() string