hostmon

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package hostmon samples host CPU/RAM/disk for the read plane (plan §4). The parsing is pure and unit-tested cross-platform; the actual /proc + statfs reads are Linux-specific (the deploy target), with a no-op stub elsewhere so the binary still builds on a dev machine.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("hostmon: host metrics not supported on this platform")

ErrUnsupported is returned by Sample on non-Linux platforms.

Functions

This section is empty.

Types

type Process

type Process struct {
	PID   int
	PPID  int
	Name  string
	State string
	RSS   uint64 // resident set size in bytes
}

Process is one host process, for the read-only "task manager" view. Only the fields needed to answer "what's using the memory" are collected — no cmdline (which can leak secrets passed as args) and no signalling capability.

func Processes

func Processes(topN int) ([]Process, error)

Processes returns the top-N host processes by resident memory (descending). It is a READ-ONLY snapshot for the UI; it never signals or mutates anything. Kernel threads (and anything with no resident memory) are skipped so the list is the userspace memory users an operator cares about. Per-pid read errors are tolerated (a process can exit mid-scan) — they're skipped, never fatal.

type Sample

type Sample struct {
	CPUPercent float64
	Load1      float64
	MemTotal   uint64
	MemUsed    uint64
	DiskTotal  uint64
	DiskUsed   uint64
}

Sample is one host metrics reading.

type Sampler

type Sampler struct {
	// contains filtered or unexported fields
}

Sampler holds the previous CPU counters so it can compute instantaneous CPU% from the delta between successive Sample calls.

func New

func New(diskPath string) *Sampler

New returns a Sampler that measures disk usage at diskPath.

func (*Sampler) Sample

func (s *Sampler) Sample() (Sample, error)

Sample reads current host metrics. CPU% is 0 on the first call (no prior counters to diff against).

Jump to

Keyboard shortcuts

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