telemetry

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CollectInterval is how often the collector takes a snapshot.
	CollectInterval = 60 * time.Second
)

Variables

View Source
var KnownRanges = map[string]QueryRange{
	"30m": {30 * time.Minute, time.Minute, "30 minutes"},
	"1h":  {time.Hour, time.Minute, "1 hour"},
	"6h":  {6 * time.Hour, 5 * time.Minute, "6 hours"},
	"24h": {24 * time.Hour, 15 * time.Minute, "24 hours"},
}

Functions

func Handler

func Handler(store *Store) http.Handler

Handler returns an http.Handler that serves the telemetry history API.

Routes:

GET /history?host=example.localhost&range=1h
GET /hosts   — list all hosts that have data

mux.Handle("/telemetry/", protect(http.StripPrefix("/telemetry", telemetry.Handler(store))))

Types

type Collector

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

Collector scrapes the live uptime data on a fixed interval and persists samples to the Store. It is deliberately decoupled from the HTTP layer — no allocations happen on the request path.

func NewCollector

func NewCollector(
	store *Store,
	hm *discovery.Host,
	res *resource.Resource,
	logger *ll.Logger,
) *Collector

NewCollector wires up the collector. Call Start() to begin sampling.

func (*Collector) Start

func (c *Collector) Start()

Start launches the background sampling goroutine. It samples immediately on start, then every CollectInterval.

func (*Collector) Stop

func (c *Collector) Stop()

Stop signals the collector to exit and waits for it to finish.

type HostSamples

type HostSamples struct {
	Host    string   `json:"host"`
	Samples []Sample `json:"samples"`
}

HostSamples is the set of samples for one host (keyed by domain).

type QueryRange

type QueryRange struct {
	Duration   time.Duration
	Resolution time.Duration // how we down-sample when returning data
	Label      string
}

QueryRange is parsed from the ?range= query parameter.

type Sample

type Sample struct {
	Timestamp   int64   `json:"ts"`              // Unix seconds
	RequestsSec float64 `json:"requests_sec"`    // req/s since last sample
	P99Ms       float64 `json:"p99_ms"`          // p99 latency in milliseconds
	ErrorRate   float64 `json:"error_rate"`      // 0.0–100.0 percent
	ActiveBE    int     `json:"active_backends"` // backends currently alive
}

Sample is one point-in-time snapshot captured every CollectInterval. Kept intentionally small — only what the UI actually graphs.

type Store

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

Store is a bbolt-backed time-series store for telemetry samples. All writes are async (non-blocking channel), reads are direct DB queries. Zero allocations on the hot path — the collector goroutine owns all writes.

func NewStore

func NewStore(dataDir expect.Folder) (*Store, error)

NewStore opens (or creates) the telemetry database at dataDir/telemetry.db.

func (*Store) Close

func (s *Store) Close() (err error)

Close flushes pending writes and closes the database. Safe to call more than once — subsequent calls are no-ops.

func (*Store) Hosts

func (s *Store) Hosts() ([]string, error)

Hosts returns all host names that have recorded data.

func (*Store) Query

func (s *Store) Query(host string, qr QueryRange) ([]Sample, error)

Query returns samples for host within the given range, down-sampled to the resolution defined by the QueryRange.

func (*Store) Record

func (s *Store) Record(host string, sample Sample)

Record enqueues a sample for async persistence. Never blocks the collector goroutine.

Jump to

Keyboard shortcuts

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