metrics

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package metrics exposes a Prometheus collector for GopherTrunk.

The `Metrics` type owns a private prometheus.Registry, registers a set of counters / gauges, and runs a goroutine that subscribes to the internal events bus and increments counters as engine events flow by. Subsystems (SDR pool, protocol decoders, recorder) push their own metrics through the public Record* methods.

The handler is exposed via Handler() so cmd/gophertrunk can mount it at /metrics on the API server.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRegistered = errors.New("metrics: collector already registered")

ErrAlreadyRegistered is returned by New when the supplied registry already has a collector with the same descriptor (used in tests).

Functions

This section is empty.

Types

type Metrics

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

Metrics owns the Prometheus registry and counters/gauges used by the daemon.

func New

func New(bus *events.Bus, pool Snapshotter, version string, detailedFEC bool) (*Metrics, error)

New constructs the metrics registry and (optionally) subscribes to the supplied events bus. Pass nil for the bus to use the metrics package purely for the manual Record* methods. Pass nil for pool to skip the SDR snapshot collector.

detailedFEC opts into the per-protocol FEC correction-depth histograms (today: gophertrunk_tetra_viterbi_corrections). They are off by default so a stock deployment doesn't carry a histogram family whose buckets only make sense to an operator profiling on-air recovery margins.

func (*Metrics) ClearIQClipRatio added in v0.3.1

func (m *Metrics) ClearIQClipRatio(system string)

ClearIQClipRatio drops the clip-ratio gauge series for system. Called alongside ClearIQPowerDbFS when a decoder pipeline tears down.

func (*Metrics) ClearIQDCRatioDb added in v0.2.5

func (m *Metrics) ClearIQDCRatioDb(system string)

ClearIQDCRatioDb drops the DC-ratio gauge series for system. Called alongside ClearIQPowerDbFS when a decoder pipeline tears down.

func (*Metrics) ClearIQPowerDbFS added in v0.1.7

func (m *Metrics) ClearIQPowerDbFS(system string)

ClearIQPowerDbFS drops the gauge series for system. Called when a decoder pipeline tears down so stale dBFS values don't linger after the SDR is no longer being driven for that system.

func (*Metrics) ClearWidebandInput added in v0.5.0

func (m *Metrics) ClearWidebandInput(serial string)

ClearWidebandInput drops both whole-capture gauge series for a dongle. Called when the wideband engine tears down.

func (*Metrics) Close

func (m *Metrics) Close() error

Close releases the subscription and waits for Run to drain. Idempotent.

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler returns an http.Handler that serves the registered metrics. Mount this at /metrics on the API server.

func (*Metrics) RecordDecodeError

func (m *Metrics) RecordDecodeError(protocol, stage string)

RecordDecodeError increments the per-protocol/stage decode-error counter.

func (*Metrics) RecordDecodeOverrun added in v0.3.1

func (m *Metrics) RecordDecodeOverrun()

RecordDecodeOverrun increments the decode-overrun counter: one live IQ chunk dropped at the decode queue because decode can't keep up with real time (issue #402). Distinct from RecordIQUnderrun, which is the SDR driver's own delivery-channel overrun.

func (*Metrics) RecordIQClipRatio added in v0.3.1

func (m *Metrics) RecordIQClipRatio(system string, ratio float64)

RecordIQClipRatio sets the rail-clipping-fraction gauge for system. The decoder computes this once per IQ-power window; the metrics package just stores it. See iqClipRatio's Help text for interpretation (issue #402).

func (*Metrics) RecordIQDCRatioDb added in v0.2.5

func (m *Metrics) RecordIQDCRatioDb(system string, ratioDb float64)

RecordIQDCRatioDb sets the DC-bin-to-total IQ power ratio gauge for system. The decoder computes this once per IQ-power window; the metrics package just stores it. See iqDCRatioDb's Help text for interpretation guidance (issue #402).

func (*Metrics) RecordIQPowerDbFS added in v0.1.7

func (m *Metrics) RecordIQPowerDbFS(system string, dbfs float64)

RecordIQPowerDbFS sets the mean-IQ-power gauge for system. Caller computes the window mean; the metrics package just stores it.

func (*Metrics) RecordIQUnderrun

func (m *Metrics) RecordIQUnderrun(driver, serial string)

RecordIQUnderrun increments the underrun counter for the supplied SDR.

func (*Metrics) RecordTetraViterbiCorrections added in v0.4.2

func (m *Metrics) RecordTetraViterbiCorrections(system, channel string, corrections int)

RecordTetraViterbiCorrections observes one TETRA §8.3.1 FEC correction-depth sample (channel bits the decode chain corrected on a recovered burst) for the given system + logical channel. No-op unless metrics.detailed_fec enabled the histogram (the common case), so the connector can wire it unconditionally without a gate of its own.

func (*Metrics) RecordUSBReconnect

func (m *Metrics) RecordUSBReconnect(driver, serial string)

RecordUSBReconnect increments the reconnect counter for the supplied SDR.

func (*Metrics) RecordWidebandInputClipRatio added in v0.5.0

func (m *Metrics) RecordWidebandInputClipRatio(serial string, ratio float64)

RecordWidebandInputClipRatio sets the whole-capture clip-ratio gauge for a wideband dongle (issue #749).

func (*Metrics) RecordWidebandInputPowerDbFS added in v0.5.0

func (m *Metrics) RecordWidebandInputPowerDbFS(serial string, dbfs float64)

RecordWidebandInputPowerDbFS sets the whole-capture power gauge for a wideband dongle (issue #749).

func (*Metrics) Registry

func (m *Metrics) Registry() *prometheus.Registry

Registry returns the underlying registry. Tests use it to scrape individual counters.

func (*Metrics) Run

func (m *Metrics) Run(ctx context.Context) error

Run consumes events from the subscription until ctx cancels. Returns nil when the subscription closed before ctx, ctx.Err() otherwise. Safe to call without a bus configured (returns immediately).

func (*Metrics) SetSDRAttached

func (m *Metrics) SetSDRAttached(driver, serial, role string, attached bool)

SetSDRAttached toggles the attached-gauge for a device.

type Snapshotter added in v0.1.7

type Snapshotter interface {
	Snapshot() []sdr.SDRStatus
}

Snapshotter is the subset of sdr.Pool the snapshot collector needs. Declared here (rather than imported from sdr) so callers can pass a nil Pool or a fake without dragging in the full sdr.Pool surface.

Jump to

Keyboard shortcuts

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