sysinfo

package
v0.8.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package sysinfo asks the operating system what a support report needs to know: the processor, memory, graphics cards, and how much room a disk has. It needs no administrator rights, changes nothing and never fails loudly: what can't be found out is left empty.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockDevice

func BlockDevice(source string) string

BlockDevice names the whole disk under /sys/block behind a mount's source (/dev/sda1 is sda; /dev/mapper/x is what the mapping sits on). "" when the source is not a local disk.

func FreeBytes

func FreeBytes(dir string) int64

FreeBytes is the room on the disk holding a folder; -1 when unknown.

func MemoryMB

func MemoryMB() int64

MemoryMB is how much memory the machine has, 0 when that can't be read. Cheap: for deciding how much work to take on (internal/pace).

func ReadCPU

func ReadCPU() (all CPUTicks, cores []CPUTicks, ok bool)

ReadCPU gives the whole machine and each core.

Types

type CPUTicks

type CPUTicks struct {
	Busy, Total uint64
}

CPUTicks is how much a processor has done since the machine started, in whatever unit its system counts. Only the difference between two readings means anything.

type Disk

type Disk struct {
	Free  int64 `json:"free"` // what this program may use
	Total int64 `json:"total"`
}

Disk is how much room a disk has.

func DiskUsage

func DiskUsage(dir string) (Disk, error)

DiskUsage is how much room there is on the disk holding a folder.

type DiskCounters

type DiskCounters struct {
	Name                  string
	ReadBytes, WriteBytes uint64
	BusyMs                uint64 // time it had something to do; 0 where a system doesn't say
}

DiskCounters is what one disk has read and written. Name is the system's: sda, nvme0n1, C:.

func ReadDiskIO

func ReadDiskIO() []DiskCounters

ReadDiskIO gives each whole disk.

type FS

type FS struct {
	Type     string `json:"type,omitempty"` // lower case: ntfs, exfat, fat32, refs, ext4, xfs, nfs, cifs, apfs...
	Kind     string `json:"kind"`           // fixed, removable, sdcard, network, optical, ram or unknown
	ReadOnly bool   `json:"readOnly,omitempty"`
	Mount    string `json:"mount,omitempty"`  // the drive's root or the mount point
	Source   string `json:"source,omitempty"` // Linux and macOS: the device or share it comes from
	// Mapped: a drive letter for a network share. Services don't see those.
	Mapped bool `json:"mapped,omitempty"`
	// UNC: named as \\server\share.
	UNC bool `json:"unc,omitempty"`
}

FS describes the file system a folder is on, as far as the operating system says without administrator rights. Whatever it won't say stays empty.

func FSInfo

func FSInfo(path string) (FS, error)

FSInfo finds the file system and kind of drive a folder is on, from the mount table and /sys.

func (FS) Network

func (f FS) Network() bool

Network says the file system is on another machine (or a share of the host, from a virtual machine or a container): locks and speed work differently.

type Info

type Info struct {
	OS        string   `json:"os"`      // "linux", "windows", "darwin"
	Arch      string   `json:"arch"`    // "amd64", "arm64"
	Release   string   `json:"release"` // the system's own name for its version
	CPU       string   `json:"cpu,omitempty"`
	Cores     int      `json:"cores"`
	MemoryMB  int64    `json:"memoryMB,omitempty"`
	FreeMB    int64    `json:"freeMemoryMB,omitempty"`
	GPUs      []string `json:"gpus,omitempty"`
	Container bool     `json:"container,omitempty"`
}

Info describes the machine.

func Read

func Read() Info

Read finds out what it can. It may read a few small files or the registry, but starts no programs.

type MemoryUse

type MemoryUse struct {
	Total, Available, SwapTotal, SwapFree uint64
}

MemoryUse is the machine's memory, in bytes.

func ReadMemory

func ReadMemory() (MemoryUse, bool)

ReadMemory gives the machine's memory.

type MountLine

type MountLine struct {
	Mount, Type, Source string
	ReadOnly            bool
}

MountLine is one line of /proc/self/mountinfo.

func FindMount

func FindMount(mountinfo, path string) (MountLine, bool)

FindMount picks the mount that holds a path from the text of /proc/self/mountinfo: the longest mount point that is the path or a folder above it. The last line wins among equals: a later mount hides an earlier one.

func ParseMountLine

func ParseMountLine(line string) (MountLine, bool)

ParseMountLine reads one line of /proc/self/mountinfo.

type NetCounters

type NetCounters struct {
	Name             string
	RxBytes, TxBytes uint64
	RxErrs, TxErrs   uint64
	Up               bool
	SpeedMbps        int64 // 0: not known
}

NetCounters is what one network interface has carried.

func ReadNetwork

func ReadNetwork() []NetCounters

ReadNetwork gives each interface, leaving out the loopback.

type ProcessUse

type ProcessUse struct {
	CPUSec  float64 // processor time used since it started
	RSS     uint64  // memory the system says it holds
	Threads int     // 0: not known
	Handles int     // open files and such; 0: not known
}

ProcessUse is this program's own share of the machine.

func ReadProcess

func ReadProcess() (ProcessUse, bool)

ReadProcess gives this program's own use.

type Temperature

type Temperature struct {
	Name    string
	Celsius float64
}

Temperature is one sensor's reading.

func ReadTemperatures

func ReadTemperatures() []Temperature

ReadTemperatures gives what the kernel's sensors say.

type Volume

type Volume struct {
	Mount  string
	Device string // the system's name for what it's on, to match with DiskCounters
	Type   string // ntfs, ext4...
	Kind   string // fixed, removable, network...
	Total  uint64
	Free   uint64
}

Volume is somewhere files can go.

func ReadVolumes

func ReadVolumes() []Volume

ReadVolumes gives each mounted file system that holds files of its own.

Jump to

Keyboard shortcuts

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