health

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package health probes scan engines for liveness and latency and exposes a snapshot for the admin console. It is protocol-agnostic: liveness checks are injected as closures, so this package does not import internal/scanner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

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

Monitor probes active scanners on a timer and classifies all registered engines for the console. Register entries with Add* before calling Start.

func NewMonitor

func NewMonitor(interval, slow time.Duration) *Monitor

NewMonitor returns a monitor that probes every interval and flags latencies above slow as warn. A non-positive interval falls back to 30s; a non-positive slow disables the warn state.

func (*Monitor) AddActive

func (m *Monitor) AddActive(name, detail string, enabled bool, probe Probe)

AddActive registers a socket scanner probed on the background timer.

func (*Monitor) AddDisabled

func (m *Monitor) AddDisabled(name, detail string)

AddDisabled registers a configured-but-unattached engine (always reported off).

func (*Monitor) AddPassive

func (m *Monitor) AddPassive(name, detail string, enabled bool, report Reporter)

AddPassive registers an engine that reports its own last outcome.

func (*Monitor) Close

func (m *Monitor) Close() error

Close stops the probe loop and waits for it to exit. Safe to call once; extra calls are no-ops.

func (*Monitor) Snapshot

func (m *Monitor) Snapshot() []ScannerHealth

Snapshot returns the current health of every registered engine, in registration order.

func (*Monitor) Start

func (m *Monitor) Start()

Start launches the background probe loop. Safe to call once; extra calls are no-ops. Call all Add* methods before Start.

type Probe

type Probe func(ctx context.Context) error

Probe checks a scanner's liveness. Used for actively-probed (socket) engines.

type Reporter

type Reporter func() Sample

Reporter returns the current passive sample for an engine that tracks its own outcomes (e.g. the osv.dev client).

type Sample

type Sample struct {
	OK      bool          // last check/scan succeeded
	Latency time.Duration // observed round-trip
	HasData bool          // false means "never checked" → unknown
}

Sample is one raw liveness observation, before classification.

type ScannerHealth

type ScannerHealth struct {
	Name      string `json:"name"`
	Detail    string `json:"detail"`
	Enabled   bool   `json:"enabled"`
	Status    Status `json:"status"`
	LatencyMS int64  `json:"latency_ms"`
}

ScannerHealth is the per-engine record surfaced in GET /api/overview.

type Status

type Status string

Status is a scan engine's health classification.

const (
	StatusOK      Status = "ok"      // reachable, latency within threshold
	StatusWarn    Status = "warn"    // reachable but slow (latency over threshold)
	StatusDown    Status = "down"    // last check failed
	StatusUnknown Status = "unknown" // not checked yet / no traffic yet
	StatusOff     Status = "off"     // configured but not attached by the active profile
)

Jump to

Keyboard shortcuts

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