gpustats

package
v0.4.153 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gpustats reads the usage of graphics cards. A figure the box does not measure is absent (nil), never 0.

Index

Constants

View Source
const (
	VendorNVIDIA = "nvidia"
	VendorAMD    = "amd"

	StateOK         = "ok"
	StateReserved   = "reserved"
	StateAsleep     = "asleep"
	StateUnreadable = "unreadable"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Index       int      `json:"index"`
	Address     string   `json:"address"` // 0000:08:00.0
	Vendor      string   `json:"vendor"`  // nvidia | amd
	Name        string   `json:"name"`
	State       string   `json:"state"`                  // ok | reserved | asleep | unreadable
	Load        *float64 `json:"load,omitempty"`         // percent
	MemoryUsed  *float64 `json:"memory_used,omitempty"`  // bytes
	MemoryTotal *float64 `json:"memory_total,omitempty"` // bytes
	Temperature *float64 `json:"temperature,omitempty"`  // °C
	Power       *float64 `json:"power,omitempty"`        // watts
}

type Config

type Config struct {
	PCIDir       string                                    // "" -> /sys/bus/pci/devices
	ReservedFile string                                    // "" -> /var/lib/casaos/gpu-reserved
	SMI          func(ctx context.Context) ([]byte, error) // nil -> nvidia-smi from the PATH; absent from the PATH = no NVIDIA figures
	NameOf       func(vendor, device string) string        // pci.ids; nil -> generic names
	Now          func() time.Time                          // nil -> time.Now
}

type Service

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

Service reads the cards in its own goroutine and keeps the last reading in memory: Latest never waits for a read.

var Default *Service

Default is the service of the running core; nil until wired.

func New

func New(cfg Config) *Service

func (*Service) Latest

func (s *Service) Latest() []Card

Latest returns copies of the cards seen so far, by rank; nil when none was ever seen.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run reads now, then every 5 s, until ctx ends.

Jump to

Keyboard shortcuts

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