Help us shape the future of Go! Take the 2026 Go Developer Survey

host

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package host reads the resource usage of the Linux machine shed runs on from procfs, sysfs, and statfs.

Counters are cumulative since boot; callers turn two readings into rates. Network and disk I/O only count physical devices, those with a device link in sysfs, so that traffic through Docker's bridges and veth pairs, loop devices, and device-mapper volumes is not counted twice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// Path is a path on the filesystem whose usage is reported; empty
	// means /.
	Path string
	// Proc and Sys are the procfs and sysfs mount points; empty means
	// /proc and /sys.
	Proc, Sys string
}

Reader reads host stats. The zero value reads /proc and /sys and reports the filesystem of /.

func (Reader) Read

func (r Reader) Read(ctx context.Context) (Stats, error)

Read returns the current stats.

type Stats

type Stats struct {
	// CPUs is the number of online CPUs.
	CPUs int
	// CPUTotal and CPUIdle are the cumulative time of all CPUs, and the
	// part of it spent idle or waiting for I/O, in clock ticks.
	CPUTotal, CPUIdle uint64
	// MemoryTotal and MemoryAvailable are in bytes. Available memory
	// includes reclaimable page cache.
	MemoryTotal, MemoryAvailable uint64
	// NetRx and NetTx are cumulative bytes over physical network interfaces.
	NetRx, NetTx uint64
	// DiskRead and DiskWrite are cumulative bytes over physical disks.
	DiskRead, DiskWrite uint64
	// DiskTotal and DiskUsed are the size and used bytes of the filesystem
	// holding the reader's path.
	DiskTotal, DiskUsed uint64
}

Stats is one reading of the host's resource usage.

Jump to

Keyboard shortcuts

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