hoststats

package
v0.4.128 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hoststats turns raw host readings into a stats.Sample.

Index

Constants

View Source
const Item = "host"

Item is the stats item id of the host.

Variables

This section is empty.

Functions

func DirForDBPath added in v0.4.90

func DirForDBPath(dbPath string) string

DirForDBPath returns the host-stats store directory under dbPath.

Types

type CPUTimes

type CPUTimes struct{ Busy, Total float64 }

type Collector

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

Collector keeps the previous Reading to compute rates. Not safe for concurrent use.

func (*Collector) Sample

func (c *Collector) Sample(r Reading) stats.Sample

Sample converts r into a Sample; a value that cannot be computed is absent.

type Config

type Config struct {
	Dir     string // /var/lib/casaos/stats/core
	Source  Source
	Clock   stats.Clock
	Publish func(name string, properties map[string]string) // the bus; errors logged by the caller
	Hub     func(name string, properties map[string]string) // alerts.Default.Handle
	Name    func() string                                   // the machine's display name, "" -> "Machine"
	Boot    func() time.Time                                // boot time, zero = unknown
}

type DiskCounters

type DiskCounters struct{ ReadBytes, WriteBytes, ReadOps, WriteOps uint64 }

type NetCounters

type NetCounters struct{ RxBytes, TxBytes, Dropped uint64 }

type Reading

type Reading struct {
	At       time.Time
	CPU      CPUTimes
	Cores    int
	MemTotal uint64
	MemUsed  uint64
	// MemCached and SwapUsed are bytes.
	MemCached, SwapUsed uint64
	Nets                map[string]NetCounters // physical interfaces only
	Disk                *DiskCounters          // nil: unreadable
	Volumes             []Volume               // nil: unreadable or none
}

type Service

type Service struct {
	Store *stats.Store
	Eval  *stats.Evaluator
	// contains filtered or unexported fields
}

Service samples the host every 5 s into Store; Eval judges its minutes.

var Default *Service

Default is the running service, nil until it started.

func New

func New(cfg Config) (*Service, error)

New opens the store and the evaluator in cfg.Dir, wires the evaluator to the store's minutes and rebuilds the host's alert counts from its history.

func (*Service) BootTime

func (s *Service) BootTime() time.Time

BootTime is the machine's boot time, zero when unknown.

func (*Service) Close

func (s *Service) Close() error

Close waits for a tick in flight, closes the store, then publishes what is queued (at most about 5 s); later calls return nil.

func (*Service) Name

func (s *Service) Name() string

Name is the machine's display name, "Machine" when unknown.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run ticks now, then every 5 s, until ctx ends. A failed tick is logged once per outage; a slow tick delays the next one, ticks never overlap.

func (*Service) Tick

func (s *Service) Tick(ctx context.Context) error

Tick takes one sample and records it. A failed Read is a gap: nothing is recorded and nothing resolves. The Store's hook judges each minute written.

type Source

type Source interface {
	Read(ctx context.Context) (Reading, error)
}

Source reads the machine; Reading.At is set by the source from its clock.

type SystemSource

type SystemSource struct {
	Now        func() time.Time                            // nil: time.Now
	Interfaces func() []string                             // the same filter as /v1/sys/utilization
	Volumes    func(ctx context.Context) ([]Volume, error) // nil: none
	IsPhysical func(name string) bool                      // /sys/block/<name>/device exists; nil: every block device
	ListEvery  time.Duration
	// contains filtered or unexported fields
}

SystemSource reads this machine. The interface list comes from a shell script, the whole-disk list from /sys and the volumes from LocalStorage: all three are kept ListEvery (1 min when zero), never read per tick, and never awaited longer than refreshWait. Read is called by one goroutine at a time.

func (*SystemSource) Read

func (s *SystemSource) Read(ctx context.Context) (Reading, error)

Read takes one reading. The CPU, memory and swap are required; the network, disk and volumes are left out when unreadable.

type Volume

type Volume struct {
	MountPoint string
	Size, Used uint64
}

Jump to

Keyboard shortcuts

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