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 ¶
const SampleSeconds = 1
SampleSeconds is how long SampleCommand takes, so callers can size their timeouts.
Variables ¶
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 ServedByLXCFS ¶ added in v1.10.7
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 ¶
Stats is a point-in-time host resource snapshot.
func ParseSample ¶ added in v1.10.2
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.