hoststats

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package hoststats reads real host CPU and memory usage from a procfs directory. The host's /proc/stat and /proc/meminfo already reflect the host (not the container cgroup) even from inside a container, so reading the process's own /proc works out of the box; binding the host's procfs to /host/proc is an optional, explicit alternative (e.g. under hardened runtimes that mask /proc). It is meaningful only for the node the process runs on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available(procPath string) bool

Available reports whether procPath exposes a readable /proc/stat, i.e. host stats can be read from it.

Types

type Stats

type Stats struct {
	CPUPercent    float64 `json:"cpu_percent"`
	MemTotalBytes uint64  `json:"mem_total_bytes"`
	MemUsedBytes  uint64  `json:"mem_used_bytes"`
	MemPercent    float64 `json:"mem_percent"`
}

Stats is a point-in-time host resource snapshot.

func Read

func Read(ctx context.Context, procPath string) (Stats, error)

Read samples host CPU (over a short interval) and memory from procPath (e.g. "/proc" or a bound "/host/proc"). Returns an error if the procfs files can't be read or parsed.

Jump to

Keyboard shortcuts

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