Help us shape the future of Go! Take the 2026 Go Developer Survey

hoststat

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package hoststat reads process-tree, network and GPU presence for soak telemetry. It does not signal processes.

Index

Constants

View Source
const (
	SpanYear  = 0
	SpanMonth = 1
	SpanWeek  = 2
	SpanDay   = 3
	SpanHour  = 4
	SpanSec   = 6
)

Timespan values match the Plex Dashboard bucket sizes: 6 second, 4 hour, 3 day, 2 ISO week, 1 month, 0 year. Resources only keeps per-second rows on the wire; coarser tiers exist so old samples stay bounded.

Variables

This section is empty.

Functions

func BucketStart

func BucketStart(t time.Time, span int, loc *time.Location) time.Time

BucketStart is the inclusive start of the timespan bucket that contains t in loc (the server's local zone).

func GPU

func GPU(devRoot string) string

GPU reports whether a render device is visible. Utilization is not inferred.

func NetDev

func NetDev(procRoot string) (rx, tx uint64, err error)

NetDev sums received and transmitted bytes across non-loopback interfaces.

Types

type Options

type Options struct {
	Now    func() time.Time
	Loc    *time.Location
	Sample func() (Sample, bool)
}

Options configure the sampler clock and the sample function (tests).

type Resources

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

Resources holds a bounded ring of host samples for this node. Clustered nodes each sample themselves; a client reads the node it connected to.

func NewResources

func NewResources(opts Options) *Resources

NewResources starts empty. Run samples once a second; tests call Add.

func (*Resources) Add

func (r *Resources) Add(s Sample)

Add records a sample into every kept timespan using a weighted average.

func (*Resources) Query

func (r *Resources) Query(span int, atMin, atMax int64, exact int64, hasExact, hasMin, hasMax bool) []Sample

Query returns samples for one kept timespan, oldest first. Unknown spans have no rows. atMin/atMax are inclusive unix seconds when the matching has* flag is set.

func (*Resources) Run

func (r *Resources) Run(ctx context.Context)

Run records one sample per second until ctx is done.

type Sample

type Sample struct {
	At         time.Time
	HostCPU    float64
	ProcessCPU float64
	HostMem    float64
	ProcessMem float64
	// contains filtered or unexported fields
}

Sample is one host/process observation at a bucket start. n is the number of observations folded into the averages and is not on the wire.

type Telemetry

type Telemetry struct {
	At           time.Time `json:"at"`
	RSSBytes     uint64    `json:"rss_bytes"`
	SelfRSS      uint64    `json:"self_rss_bytes"`
	HeapAlloc    uint64    `json:"heap_alloc"`
	HeapInuse    uint64    `json:"heap_inuse"`
	HeapSys      uint64    `json:"heap_sys"`
	HeapIdle     uint64    `json:"heap_idle"`
	HeapReleased uint64    `json:"heap_released"`
	GOGC         int       `json:"gogc"`
	FDs          int       `json:"fds"`
	SQLiteFDs    int       `json:"sqlite_fds"`
	Goroutines   int       `json:"goroutines"`
	FFmpeg       int       `json:"ffmpeg"`
	Sessions     int       `json:"sessions"`
	Transcodes   int       `json:"transcodes"`
	Children     int       `json:"children"`
	RetryQueue   int       `json:"retry_queue"`
	NetRx        uint64    `json:"net_rx_bytes"`
	NetTx        uint64    `json:"net_tx_bytes"`
	GPU          string    `json:"gpu"`
	Valid        bool      `json:"valid"`
	Error        string    `json:"error,omitempty"`
}

Telemetry is one soak sample. Session counts are supplied by the caller.

func Collect

func Collect(procRoot, devRoot string, pid, sessions, transcodes int) Telemetry

Collect reads the process tree, network counters and GPU presence.

type Tree

type Tree struct {
	RSSBytes     uint64
	SelfRSS      uint64
	FDs          int
	SQLiteFDs    int
	Children     int
	FFmpegPIDs   []int
	GuardianPIDs []int
}

Tree is one process and its descendants.

func ProcessTree

func ProcessTree(procRoot string, pid int) (Tree, error)

ProcessTree sums RSS and file descriptors for pid and its descendants. ffmpeg and encoder-guardian pids are listed separately and are included in the sums.

Jump to

Keyboard shortcuts

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