metrics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package metrics defines and registers all Prometheus metrics for sqi-server.

Callers obtain a *Metrics via New and pass it to the components that record observations. Using a private prometheus.Registry rather than the global default registry prevents cross-contamination between test instances and avoids collision with Go runtime metrics.

Many of the metric families defined here are stubs whose values are set to zero until the corresponding component lands:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct {

	// HTTPRequestsTotal counts completed HTTP requests, labeled by HTTP
	// method, request path, and response status code.
	//
	// TODO: switch the "path" label to chi's route pattern
	// (chi.RouteContext(r.Context()).RoutePattern()) to avoid high cardinality
	// from parameterised segments such as /api/v1/jobs/{id}.
	HTTPRequestsTotal *prometheus.CounterVec

	// HTTPRequestDuration records request latency in seconds, labeled by HTTP
	// method and request path.
	HTTPRequestDuration *prometheus.HistogramVec

	// SchedulerQueueDepth is the current number of ready tasks waiting for
	// assignment in each named queue. Set by the scheduler.
	SchedulerQueueDepth *prometheus.GaugeVec

	// SchedulerTasksTotal counts task completions, labeled by queue name and
	// terminal status (succeeded, failed, canceled). Incremented by the
	// scheduler.
	SchedulerTasksTotal *prometheus.CounterVec

	// SchedulerAssignmentDuration records the wall-clock time spent in a
	// single call to tryAssign, labeled by result:
	//   - "assigned"  — a worker was found and the task was dispatched.
	//   - "deferred"  — no eligible worker or policy blocked; task stays ready.
	//   - "error"     — an unexpected error aborted the attempt.
	//
	// Populated by the scheduler assignment loop.
	SchedulerAssignmentDuration *prometheus.HistogramVec

	// SchedulerIdleWorkers is the current count of online workers that have no
	// task in 'assigned' or 'running' state, partitioned by farm ID.
	// Updated by the scheduler after each worker-registry or sweep event.
	SchedulerIdleWorkers *prometheus.GaugeVec

	// WorkersTotal is the current number of registered workers, partitioned by
	// status: online, offline, or disabled. Set by the worker registry.
	WorkersTotal *prometheus.GaugeVec

	// NATSPublishedTotal counts messages published to the embedded NATS broker,
	// labeled by subject. Incremented by the typed bus client.
	NATSPublishedTotal *prometheus.CounterVec

	// NATSConsumedTotal counts messages consumed from the embedded NATS broker,
	// labeled by subject. Incremented by the typed bus client.
	NATSConsumedTotal *prometheus.CounterVec

	// DBQueryDuration records SQLite query execution time in seconds, labeled
	// by operation name (e.g. "job.insert", "task.list"). Observed by the store
	// implementation.
	DBQueryDuration *prometheus.HistogramVec

	// UsageActiveClaims is the current number of active (unreleased)
	// usage-pool claims for each named pool. Updated by the scheduler on every
	// dispatch tick.
	UsageActiveClaims *prometheus.GaugeVec

	// TaskRetriesTotal counts tasks re-queued by automatic retry, partitioned
	// by queue name. Incremented by the scheduler's failure fork.
	TaskRetriesTotal *prometheus.CounterVec

	// JobsAutoParkedTotal counts jobs auto-parked at their failure limit,
	// partitioned by queue name. Incremented by the scheduler's failure fork.
	JobsAutoParkedTotal *prometheus.CounterVec
	// contains filtered or unexported fields
}

Metrics holds every Prometheus metric family for sqi-server and the isolated registry they are registered against. Obtain one with New.

func New

func New() *Metrics

New creates a *Metrics and registers all metric families — plus the standard Go runtime and process collectors — against a fresh prometheus.Registry.

func (*Metrics) Handler

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

Handler returns an http.Handler that serves the Prometheus text exposition format (and OpenMetrics when the client requests it) for all metrics registered in this *Metrics' private registry.

Jump to

Keyboard shortcuts

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