Documentation
¶
Overview ¶
Package stats reads cheap per-container resource usage via `podman stats` and exposes a structured view both lerd-ui (for the dashboard widget) and the TUI (for its Dashboard pane) can share. Lives outside internal/ui so the TUI can call it in-process without pulling in the HTTP server stack.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes turns a byte count into a short human string ("128MB", "2.4GB"). Used by both the TUI dashboard and lerd-ui's resources widget so the units they show match.
func SetHostReader ¶ added in v1.25.0
func SetHostReader(fn func() ([]ContainerStat, error)) (restore func())
SetHostReader swaps the host-process reader for tests so Read doesn't shell out to systemctl (which would also add the ~1s CPU-sample sleep).
func SetReader ¶
func SetReader(fn func() ([]ContainerStat, error)) (restore func())
SetReader swaps the underlying container reader for tests so callers can drive Read from a fixture without shelling out to podman.
Types ¶
type ContainerStat ¶
type ContainerStat struct {
Name string `json:"name"`
CPUPercent float64 `json:"cpu_percent"`
MemBytes int64 `json:"mem_bytes"`
MemLimit int64 `json:"mem_limit_bytes"`
MemPercent float64 `json:"mem_percent"`
}
ContainerStat is one row of resource usage for a single lerd-prefixed container. Mirrors the JSON the web UI consumes so callers can serialize directly without an adapter struct.
func ParseRows ¶
func ParseRows(text string) []ContainerStat
ParseRows turns multi-line `podman stats --format …` output into a slice of ContainerStat. Exported so tests for either caller can build inputs without a real podman.
type Snapshot ¶
type Snapshot struct {
Containers []ContainerStat `json:"containers"`
TotalCPUPercent float64 `json:"total_cpu_percent"`
TotalMemBytes int64 `json:"total_mem_bytes"`
HostMemBytes int64 `json:"host_mem_bytes"`
UpdatedAt time.Time `json:"updated_at"`
Available bool `json:"available"`
}
Snapshot is the aggregated view returned by Read. Totals are summed server-side so multiple subscribers don't each re-aggregate.