hoststat

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package hoststat reads host-level CPU, memory and disk usage from /proc and the filesystem. It has no dependencies on the rest of the codebase so both the server's resource service and the remote agent collector can use it.

Index

Constants

View Source
const (
	OSSourceHostFile       = "host_file"
	OSSourceKubernetesNode = "kubernetes_node"
)

Source values of an OSRelease.

View Source
const (
	OSReasonMountMissing   = "mount_missing"
	OSReasonFileUnreadable = "file_unreadable"
	OSReasonNodeNotFound   = "node_not_found"
)

Reasons why an OSRelease carries no identity.

Variables

This section is empty.

Functions

func DiskUsage

func DiskUsage(path string) (total uint64, used uint64)

DiskUsage returns total and used bytes of the filesystem holding path. Returns (0, 0) if the filesystem cannot be stat'd.

Types

type OSRelease added in v1.7.0

type OSRelease struct {
	ID                string
	VersionID         string
	PrettyName        string
	Source            string
	UnavailableReason string
}

OSRelease identifies the operating system of a host.

func ParseOSImage added in v1.7.0

func ParseOSImage(osImage string) OSRelease

ParseOSImage derives an operating system identity from a Kubernetes node osImage string. An unrecognised string keeps its pretty name and no version.

func ReadOSRelease added in v1.7.0

func ReadOSRelease() OSRelease

ReadOSRelease returns the host operating system identity, or the reason it could not be read.

type Reader

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

Reader samples host CPU and memory at 1s intervals via /proc. It runs its own goroutine, independent of any container collector.

func NewReader

func NewReader() *Reader

NewReader creates a reader and takes an initial CPU sample.

func (*Reader) CPUPercent

func (r *Reader) CPUPercent() float64

CPUPercent returns the latest host CPU usage percentage (0-100).

func (*Reader) MemTotal

func (r *Reader) MemTotal() int64

MemTotal returns host total memory in bytes.

func (*Reader) MemUsed

func (r *Reader) MemUsed() int64

MemUsed returns host memory used in bytes.

func (*Reader) Start

func (r *Reader) Start(ctx context.Context)

Start runs the sampling goroutine. Blocks until ctx is cancelled.

Jump to

Keyboard shortcuts

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