Documentation
¶
Overview ¶
Package procmon samples live CPU/memory for the daemon's per-turn process groups, on demand.
Every turn runs in its own process group (see internal/proc); the group-leader pid is the whole process tree for that turn (bash → node → claude/codex/opencode). The Supervisor Track()s a turn's group-leader pid for the turn's lifetime and Untrack()s it at teardown, labelling it (agent, chatId, runId). A Monitor samples every tracked group on a ticker and broadcasts Frames to subscribers — but ONLY while at least one subscriber is connected: the sampler goroutine starts on the first Subscribe and stops on the last unsubscribe. So an idle daemon that nobody is watching does ZERO background work (no goroutine, no /proc scans) — this is the on-demand / no-leak guarantee the console's Agent page relies on.
The sampler itself is platform-split (sample_linux.go / sample_darwin.go / sample_other.go), mirroring internal/proc; the lifecycle and delta math here are platform-independent.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Frame ¶
type Frame struct {
At string `json:"at"` // RFC3339 timestamp of the tick
Samples []Sample `json:"samples"`
}
Frame is one sampling tick: every currently-tracked turn that had a live process this tick. An empty Samples slice (with no running turns, or between ticks) is a valid, meaningful frame.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor is the refcounted shared sampler. One per Supervisor; Track/Untrack are driven by the turn lifecycle and Subscribe by SSE clients. All state is guarded by mu.
func NewMonitor ¶
func NewMonitor() *Monitor
NewMonitor builds an idle monitor: no sampler goroutine runs until the first Subscribe.
func (*Monitor) Subscribe ¶
Subscribe registers a frame channel and starts the sampler if this is the first subscriber. The returned cancel removes the subscriber and stops the sampler when the last one leaves — so sampling happens only while something is watching. ok=false if the subscriber cap is reached; the caller should serve a 503-style response and not block.
type Sample ¶
type Sample struct {
Agent string `json:"agent"`
ChatID string `json:"chatId"`
RunID string `json:"runId"`
Pid int `json:"pid"`
CPUPercent float64 `json:"cpuPercent"`
RSSBytes uint64 `json:"rssBytes"`
}
Sample is one running turn's live resource use at a single tick. Labels + numbers only — never any secret. RSSBytes is resident set size (physical memory) summed over the whole process group.