hoststats

package
v1.10.13 Latest Latest
Warning

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

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

Documentation

Overview

Package hoststats re-exports the procfs readers in pkg/hoststats for existing callers and adds the helper-container sampler, which is control-plane only.

Index

Constants

View Source
const SampleSeconds = 1

SampleSeconds is how long SampleCommand takes, so callers can size their timeouts.

Variables

View Source
var SampleCommand = []string{
	"sh", "-c",
	"grep '^cpu ' /proc/stat; sleep 1; grep '^cpu ' /proc/stat; " +
		"grep -E '^(MemTotal|MemAvailable|MemFree|Buffers|Cached):' /proc/meminfo",
}

SampleCommand is run inside a short-lived container on a node to produce one sample. A container's /proc/stat and /proc/meminfo are the HOST's — they are not namespaced — so this reads the node's real CPU and memory without binding anything. It is the fallback for nodes whose agent does not push stats (no agent at all, or an older one).

The two cpu lines a second apart are the CPU sample window; the meminfo keys cover kernels with and without MemAvailable.

Functions

func Available

func Available(procPath string) bool

Available reports whether procPath exposes a readable /proc/stat.

func ServedByLXCFS added in v1.10.7

func ServedByLXCFS(procPath string) bool

ServedByLXCFS reports whether procPath's stat or meminfo is an lxcfs mount, as on an LXC guest. lxcfs answers for the cgroup of the process reading the file, so from inside a container it reports that container's own usage rather than the host's.

Types

type Stats

type Stats = hoststats.Stats

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

func ParseSample added in v1.10.2

func ParseSample(out string) (Stats, error)

ParseSample turns SampleCommand's output into a snapshot. It is deliberately a pure string function: the container is run by the caller, which owns the Docker client, so the parsing stays testable without one.

func Read

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

Read samples host CPU and memory from procPath.

Jump to

Keyboard shortcuts

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