dmidecode

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dmidecode provides a data source that runs the external `dmidecode --type 17` command and parses its SMBIOS Memory Device entries into typed structs describing installed DIMMs.

DIMM inventory is static, so the first successful call to MemoryDevices() caches the result permanently (mirrors the lscpu source's sync.Once idiom). The source is a process-wide singleton (Default); tests inject mock output via SetMock. dmidecode typically requires root; when unavailable or permission-denied, Available() returns false and MemoryDevices() returns an error so the caller can gracefully degrade.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetMock

func SetMock(out string)

SetMock injects canned `dmidecode --type 17` output for testing (clears the cache so the next call re-parses the mock).

func SetSystemMock

func SetSystemMock(out string)

SetSystemMock injects canned `dmidecode --type 1` output for testing.

Types

type MemoryDevice

type MemoryDevice struct {
	Locator      string // e.g. "DIMM0"
	Type         string // e.g. "DDR4"; empty for empty slot
	Speed        string // e.g. "3200 MT/s"
	Manufacturer string
	SizeMB       int // 0 for "No Module Installed"
}

MemoryDevice holds one SMBIOS Memory Device (type 17) entry.

type Source

type Source interface {
	// MemoryDevices returns all DIMM entries (including empty slots, which
	// have SizeMB=0). Cached after the first successful call.
	MemoryDevices() ([]MemoryDevice, error)
	// SystemInfo returns the SMBIOS type 1 (System Information) entry.
	// Cached after the first successful call; nil if dmidecode is unavailable.
	SystemInfo() (*SystemInfo, error)
	// Available reports whether dmidecode is on PATH. Note: root permission
	// to actually read SMBIOS is verified at call time, not here.
	Available() bool
}

Source is the typed interface for the dmidecode data source.

func Default

func Default() Source

type SystemInfo

type SystemInfo struct {
	Manufacturer string // e.g. "Supermicro"
	ProductName  string // e.g. "X12STW-F" (board/product); "To be filled by O.E.M." when unset
	Version      string // product version / board revision
	Serial       string // system serial number
}

SystemInfo holds the SMBIOS System Information (type 1) entry describing the server/device identity. Static; cached permanently after the first call.

Jump to

Keyboard shortcuts

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