system

package
v1.19.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package system encapsulates host-level resource probing used by the WebSocket system stats endpoint: cgroup limits and GPU detection/stats. The types here own their own caching and synchronization so handlers can hold them as plain fields.

Index

Constants

View Source
const AMDGPUSysfsPath = "/sys/class/drm"

AMDGPUSysfsPath is the sysfs base used to discover AMD GPUs.

Variables

This section is empty.

Functions

func HasAMDGPU

func HasAMDGPU() bool

HasAMDGPU reports whether a card with mem_info_vram_total exists under AMDGPUSysfsPath.

Types

type CgroupCache

type CgroupCache struct {
	// contains filtered or unexported fields
}

CgroupCache memoizes the result of cgroup limit detection for a configurable TTL. A single in-flight refresh is shared across concurrent callers (singleflight semantics via the write lock), so a stampede of system-stats samplers never duplicates the work.

func NewCgroupCache

func NewCgroupCache(ttl time.Duration) *CgroupCache

NewCgroupCache returns a cache that caches detection results for ttl using the default docker.DetectCgroupLimits detector.

func NewCgroupCacheWithDetector

func NewCgroupCacheWithDetector(ttl time.Duration, detector func() (*docker.CgroupLimits, error)) *CgroupCache

NewCgroupCacheWithDetector returns a cache backed by a custom detector. Useful when callers (e.g. tests) need to control detection behaviour or simulate failures.

func (*CgroupCache) Get

func (c *CgroupCache) Get() *docker.CgroupLimits

Get returns the cached cgroup limits, refreshing if the entry is older than the TTL. Returns nil when no cgroup limits have been detected (host is not running under cgroups).

type GPUMonitor

type GPUMonitor struct {
	// contains filtered or unexported fields
}

GPUMonitor probes for an attached GPU (NVIDIA / AMD / Intel) and reports VRAM usage. Detection is cached for gpuDetectionTTL; once a vendor is detected, subsequent Stats calls invoke the vendor-specific tool directly.

func NewGPUMonitor

func NewGPUMonitor(enabled bool, configuredType string) *GPUMonitor

NewGPUMonitor creates a monitor. enabled gates Stats; when false, Stats returns (nil, nil). configuredType is the user-pinned vendor ("nvidia"|"amd"|"intel"|"auto"|"") — anything else falls back to auto-detection.

func (*GPUMonitor) Enabled

func (m *GPUMonitor) Enabled() bool

Enabled reports whether GPU monitoring is on.

func (*GPUMonitor) Stats

func (m *GPUMonitor) Stats(ctx context.Context) ([]systemtypes.GPUStats, error)

Stats returns per-GPU VRAM stats. Returns (nil, 0, nil) when monitoring is disabled or no GPU is detected; vendor-specific errors are propagated otherwise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL