hostinfo

package
v1.60.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package hostinfo reads what the machine the cockpit runs on is up to: how busy it is, how much memory is in use, and how full the disk under the projects is. Three percentages, cheap enough to read while a browser is connected, and nothing to configure.

Everything here stays free of cgo, because the released binaries are built that way. On Linux the kernel publishes its busy counters in /proc/stat, so the busy number there is the real share of the cores at work, the delta between two readings. macOS keeps the same counters behind mach calls that would need cgo, so there the busy number stays the load average against the core count: already averaged over a minute, and it may pass 100 percent when more work is queued than the machine can run at once. That is information, not a bug, and the CPU label says which of the two the number is.

Index

Constants

View Source
const (
	Warn = 80
	Crit = 95
)

Warn and Crit are the thresholds a surface colors on: quiet below Warn, yellow from Warn, red from Crit.

Variables

This section is empty.

Functions

func Bar

func Bar(percent int) int

Bar caps a percentage at 100 for the width of a progress bar. The number next to it keeps the real value.

Types

type Cache

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

Cache reads at most once per interval, so every connected browser shares one reading instead of each heartbeat costing its own.

func NewCache

func NewCache(path string, ttl time.Duration) *Cache

NewCache reads the disk of the filesystem path sits on.

func (*Cache) Stats

func (c *Cache) Stats() Stats

Stats returns the current reading, refreshing it when the cached one aged out.

type Stats

type Stats struct {
	HasCPU  bool `json:"hasCpu"`
	HasMem  bool `json:"hasMem"`
	HasDisk bool `json:"hasDisk"`

	CPUPercent  int `json:"cpu"`
	MemPercent  int `json:"mem"`
	DiskPercent int `json:"disk"`

	CPULabel  string `json:"cpuLabel"`
	MemLabel  string `json:"memLabel"`
	DiskLabel string `json:"diskLabel"`

	// Level is "", "warn" or "crit", taken from the worst of the readings.
	Level string `json:"level"`
}

Stats is one reading. A metric the platform could not answer keeps its Has flag false and its percentage at -1, so a surface can leave that row out instead of showing a zero that would read as "idle".

func (Stats) Any

func (s Stats) Any() bool

Any reports whether the reading carries a single usable number.

func (Stats) Worst

func (s Stats) Worst() int

Worst is the highest of the readings, the one the color follows.

Jump to

Keyboard shortcuts

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