hostmetrics

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package hostmetrics reads one machine's own counters: CPU, memory, disk, network. It is a leaf on purpose. Both the panel's sampler and the node agent take this reading, and the agent must not import infra/metrics for it: metrics imports managedtiles, and that edge closed the cycle that kept managedtiles from importing the node-aware runtime (docs/plans/35-cluster.md).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcNetPath

func ProcNetPath(file string) string

ProcNetPath resolves a /proc/net file in the HOST network namespace. /proc/net symlinks to /proc/self/net, so through a HOST_PROC bind mount it would show the container's own netns, pid 1's net dir is the host's. Exported for the panel's conntrack flow sampler, which reads the same tree.

Types

type HostCounters

type HostCounters struct {
	At time.Time

	CPUIdle, CPUTotal uint64
	RxBytes, TxBytes  uint64
	MemUsed           int64
	DiskUsed          int64

	// OK is false when /proc could not be read at all, which is every
	// non-Linux platform. A sample is never derived from one.
	OK bool
}

HostCounters is one raw reading of the machine's own counters: cumulative CPU jiffies, cumulative network bytes, and the point-in-time memory and disk figures. Two readings make a sample.

Exported because the node agent takes the same reading on a worker and posts it to the panel, the graphs on a worker's server page are the same graphs as the manager's, so the numbers behind them have to be measured the same way (docs/plans/32-multi-node-ui.md, host metrics).

func ReadHost

func ReadHost(now time.Time) HostCounters

ReadHost takes one reading. Linux only; elsewhere OK is false.

func (HostCounters) Sample

func (c HostCounters) Sample(prev HostCounters) (HostSample, bool)

Sample turns the previous reading and this one into rates. ok is false on the first reading, on a counter reset, and on any platform ReadHost cannot serve, in each case there is a reading to keep but no sample to store.

type HostSample

type HostSample struct {
	CPUPct   float64
	MemBytes int64
	RxBps    float64
	TxBps    float64
	DiskUsed int64
}

HostSample is two readings turned into rates and levels.

Jump to

Keyboard shortcuts

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