Documentation
¶
Overview ¶
Package machine reads the numbers that decide whether the workstation survives the next hour: RAM and swap, memory pressure, the Claude Desktop cgroup, tmpfs and disk, build slots, kind clusters and the kernel's OOM kills. Linux only: /proc, cgroup v2 and the journal.
Index ¶
- Constants
- func FindMemcapScope(unit string) string
- func FindScope() string
- func GTTUsedMiB(gpus []GPU) int
- func OOMDSwapLimit() int
- func ParseOllamaLoads(journal string) map[string]string
- func ParseOomd(journal string) []string
- func ReadCPUPSISome10() (float64, error)
- func ReadForks() (uint64, error)
- func ReadLoad() ([3]float64, error)
- func ReadPSIFull60() (float64, error)
- func SwapoffRuns() bool
- func UnloadLemonade(ctx context.Context, url, model string) error
- func UnloadOllama(ctx context.Context, url, model string) error
- func Zone() (*time.Location, error)
- type Cluster
- type Disk
- type GPU
- type HostModel
- type Mem
- type OOMKill
- type Scope
- type Slot
Constants ¶
const ( Ollama = "ollama" Lemonade = "lemonade" )
The host's model servers, which load models into the iGPU's memory.
const DefaultOOMDSwapLimit = 90
DefaultOOMDSwapLimit is systemd-oomd's SwapUsedLimit when no oomd.conf sets it: the percent of swap in use at which it kills the monitored cgroup's largest swap user, however much RAM is free.
Variables ¶
This section is empty.
Functions ¶
func FindMemcapScope ¶ added in v0.14.0
FindMemcapScope returns the cgroup of the capped run's scope unit (as a run event names it, "memcap-….scope"), or "" when it has ended.
func FindScope ¶
func FindScope() string
FindScope returns the largest Claude Desktop scope, or "" when none runs.
func GTTUsedMiB ¶ added in v0.38.0
GTTUsedMiB is the GTT all devices pin.
func OOMDSwapLimit ¶ added in v0.37.4
func OOMDSwapLimit() int
OOMDSwapLimit returns systemd-oomd's SwapUsedLimit in percent: the last setting in oomd.conf and its drop-ins, DefaultOOMDSwapLimit without one.
func ParseOllamaLoads ¶ added in v0.38.0
ParseOllamaLoads maps each model blob to the address of the client whose request loaded it last: the first model request logged after the load that started before it (gin logs a request when it ends, with its latency). A blob whose last load's request is still running maps to "": an earlier load's client is not its.
func ParseOomd ¶ added in v0.45.2
ParseOomd keeps the lines of systemd-oomd's journal where it killed a cgroup: the event that takes every session down at once.
func ReadCPUPSISome10 ¶ added in v0.38.1
ReadCPUPSISome10 returns CPU pressure "some avg10" in percent: the share of the last ten seconds in which at least one runnable task waited for a CPU.
func ReadForks ¶ added in v0.42.0
ReadForks returns the processes forked since boot: the "processes" line of /proc/stat.
func ReadPSIFull60 ¶
ReadPSIFull60 returns memory pressure "full avg60" in percent: the share of the last minute in which every task stalled on memory.
func SwapoffRuns ¶ added in v0.37.6
func SwapoffRuns() bool
SwapoffRuns reports whether a swapoff process runs. While swapoff drains a device the kernel has already taken the device out of SwapTotal, but its pages still count as used, so swap reads near 100 % full while it is being emptied.
func UnloadLemonade ¶ added in v0.45.0
UnloadLemonade asks the Lemonade Server at url to drop model from memory now (POST /api/v1/unload); its weights stay on disk.
func UnloadOllama ¶ added in v0.40.0
UnloadOllama asks the ollama at url to drop model from memory now; its weights stay on disk and the next request loads it again.
Types ¶
type Cluster ¶
type Cluster struct {
Name string `json:"name"`
Nodes int `json:"nodes"`
MemMiB int `json:"memMiB"`
// Containers are the node containers' full ids.
Containers []string `json:"containers"`
// RunningFor is docker's age of its oldest node ("2 hours ago").
RunningFor string `json:"runningFor"`
}
Cluster is a running kind cluster.
type Disk ¶
type Disk struct {
Path string `json:"path"`
UsedMiB int `json:"usedMiB"`
FreeMiB int `json:"freeMiB"`
// TotalMiB is the filesystem's size.
TotalMiB int `json:"totalMiB"`
}
Disk is a filesystem's usage in MiB.
type GPU ¶ added in v0.38.0
type GPU struct {
Device string `json:"device"`
GTTUsedMiB int `json:"gttUsedMiB"`
GTTTotalMiB int `json:"gttTotalMiB"`
VRAMUsedMiB int `json:"vramUsedMiB"`
VRAMTotMiB int `json:"vramTotalMiB"`
}
GPU is an amdgpu device's memory in MiB. On an APU, GTT is system RAM the driver pins for the GPU: no cgroup counts it, but it is gone from MemAvailable all the same.
type HostModel ¶ added in v0.45.0
type HostModel struct {
// Server is the model server holding it: Ollama or Lemonade.
Server string `json:"server"`
Name string `json:"name"`
SizeMiB int `json:"sizeMiB"`
// GPUMiB is the part on the GPU: on an APU, GTT.
GPUMiB int `json:"gpuMiB,omitempty"`
ExpiresAt time.Time `json:"expiresAt,omitzero"`
// Client is who sent the request that loaded it, as the server's log
// shows it or, while that request still runs, as the one client
// connected to the server: an address, with the kind node's name when
// one has it.
Client string `json:"client,omitempty"`
}
HostModel is a model one of the host's model servers holds in memory.
func LemonadeModels ¶ added in v0.45.0
LemonadeModels asks the Lemonade Server at url which models it holds (GET /api/v1/health) and how large each one's weights are (GET /api/v1/models, in GB). Lemonade logs no client address: a model's client is the one peer connected to url's port, and none when several are. An empty url means none is watched.
func OllamaModels ¶ added in v0.38.0
func OllamaModels(ctx context.Context, url, unit string, serviceLog func(ctx context.Context, unit, grep string) ([]byte, error)) ([]HostModel, error)
OllamaModels asks the ollama at url which models it holds (GET /api/ps) and finds each one's loading client in the log of unit (serviceLog). A load whose request still runs is not in the journal yet: its client is the one peer connected to url's port, and none when several are. An empty url means none is watched.
func (HostModel) Label ¶ added in v0.45.0
Label is the model's name after its server's, as the watch prints it.
type Mem ¶
type Mem struct {
TotalMiB int `json:"totalMiB"`
AvailableMiB int `json:"availableMiB"`
SwapTotalMiB int `json:"swapTotalMiB"`
SwapUsedMiB int `json:"swapUsedMiB"`
ShmemMiB int `json:"shmemMiB"`
}
Mem is /proc/meminfo in MiB.
func (Mem) OOMDHeadroomMiB ¶ added in v0.37.4
OOMDHeadroomMiB is the swap growth left before systemd-oomd's trigger at limit percent; negative once swap is past it.
type OOMKill ¶
type OOMKill struct {
At time.Time `json:"at"`
PID int `json:"pid"`
Task string `json:"task"`
AnonMiB int `json:"anonMiB"`
Constraint string `json:"constraint,omitempty"`
// Memcg is the cgroup whose limit was hit: a memcap scope, a kind
// lab's pod, or the desktop scope.
Memcg string `json:"memcg,omitempty"`
}
OOMKill is one process the kernel killed for memory.
type Scope ¶
type Scope struct {
Path string `json:"path"`
CurrentMiB int `json:"currentMiB"`
AnonMiB int `json:"anonMiB"`
SwapMiB int `json:"swapMiB"`
High string `json:"high"`
Max string `json:"max"`
SwapMax string `json:"swapMax"`
OOMKills int64 `json:"oomKills"`
HighEvents int64 `json:"highEvents"`
}
Scope is the Claude Desktop cgroup: every session's CLI and MCP servers live in it, and systemd-oomd kills it whole.