health

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package health provides system health metrics collection and reporting.

Index

Constants

View Source
const MAX_WINDOW_SECONDS = 900

MAX_WINDOW_SECONDS is the maximum number of samples to keep in memory (15 minutes, as used by the Report type)

Variables

This section is empty.

Functions

func ReportLoop

func ReportLoop(ctx context.Context, logger *slog.Logger, reportInterval time.Duration, cfg ReportConfig, publish func(Report) error)

ReportLoop collects metrics and invokes the publish callback on each interval.

Types

type Collector

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

Collector is used to sample and store system metrics for reporting rolling averages over a period of time.

func NewCollector

func NewCollector(interval time.Duration) (*Collector, error)

NewCollector creates a new metrics Collector. @param internval - the number of seconds between samples, zero means 5 secs.

func (Collector) Averages

func (c Collector) Averages(windowSeconds int) (Metrics, error)

Averages returns a Metrics struct containing the averages of each metric over the sampling window `windowSeconds`.

func (*Collector) Sample

func (c *Collector) Sample() error

Sample adds a sample to the Collector metrics, and unshifts the relevant slices if the window size is reached.

func (*Collector) Start

func (c *Collector) Start(ctx context.Context, logger *slog.Logger)

Start starts sampling the system metrics at the specified interval. It will stop when the context is cancelled.

func (Collector) Timing

func (c Collector) Timing() struct {
	Started     time.Time
	WindowStart time.Time
	WindowEnd   time.Time
}

Timing returns the timestamp of when the Collector was created plus the timestamp of the first and last sample in the window.

type Metrics

type Metrics struct {
	// CPU Usage (percentage)
	CPUUsage     float64   `json:"cpu_usage"`
	CPUCoreUsage []float64 `json:"cpu_core_usage"`
	// Memory Usage (percentage)
	MemoryUsage float64 `json:"memory_usage"`
	// Network I/O (bytes)
	NetworkBytesSent     float64 `json:"network_bytes_sent"`
	NetworkBytesReceived float64 `json:"network_bytes_received"`
	// Disk Usage (percentage)
	DiskUsed       float64 `json:"disk_used"`
	DiskInodesUsed float64 `json:"disk_inodes_used"`
	// Disk I/O (bytes)
	DiskBytesRead    float64 `json:"disk_bytes_read"`
	DiskBytesWritten float64 `json:"disk_bytes_written"`
}

Metrics holds metrics averages for a period of time e.g. last 1 minute

type Report

type Report struct {
	InstanceID        string
	Version           string             `json:"version"`
	Timestamp         time.Time          `json:"timestamp"`
	Count             int                `json:"count"`
	Started           time.Time          `json:"started"`
	WindowStart       time.Time          `json:"window_start"`
	WindowEnd         time.Time          `json:"window_end"`
	Uptime            uint64             `json:"uptime"`
	OneMinute         Metrics            `json:"one_minute"`
	FiveMinutes       Metrics            `json:"five_minutes"`
	FifteenMinutes    Metrics            `json:"fifteen_minutes"`
	Files             map[string]string  `json:"files"`
	TerminationNotice *TerminationNotice `json:"termination_notice,omitempty"`
	ConfigHash        string             `json:"config_hash,omitempty"` // Runtime config hash
}

Report hold a report of metrics to be serialised to JSON by JSONPusher

func NewReport

func NewReport(collector *Collector, count int, cfg ReportConfig) (Report, error)

NewReport creates a new agent Report with averages from Collector metrics

type ReportConfig

type ReportConfig struct {
	InstanceID  string
	RecvDir     string
	IdentityDir string // Path to identity directory for reading config.hash
	// GetTerminationNotice returns the current spot termination notice, if any
	GetTerminationNotice func() *TerminationNotice
}

ReportConfig provides the runtime config required to build metrics reports.

type TerminationNotice

type TerminationNotice struct {
	Action   string    `json:"action"`
	Deadline time.Time `json:"deadline,omitempty"`
}

TerminationNotice represents a spot instance termination notice

Jump to

Keyboard shortcuts

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