metrics

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package metrics provides a Prometheus-compatible metrics endpoint and built-in framework metrics (HTTP request duration, active connections, etc.).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

type Registry struct {

	// HTTP metrics
	RequestDuration *prometheus.HistogramVec
	RequestsTotal   *prometheus.CounterVec
	ActiveRequests  prometheus.Gauge

	// Queue metrics
	JobsProcessed *prometheus.CounterVec
	JobsFailed    *prometheus.CounterVec

	// WebSocket metrics
	WebSocketConns prometheus.Gauge
	// contains filtered or unexported fields
}

Registry wraps a Prometheus registry with framework-specific metrics.

func New

func New() *Registry

New creates a Registry with built-in framework metrics registered.

func (*Registry) Handler

func (r *Registry) Handler(authorize func(*http.Request) bool) http.Handler

Handler returns the Prometheus /metrics HTTP handler, guarded by authorize.

/metrics discloses internal route names, traffic volumes, and process detail, so it must not be exposed unauthenticated. authorize runs on every scrape; return true to allow. Passing nil fails closed (every request gets 403) — to intentionally expose metrics without app-level auth (e.g. when the endpoint is isolated at the network layer), pass a function that always returns true.

func (*Registry) Middleware

func (r *Registry) Middleware(next http.Handler) http.Handler

Middleware returns an HTTP middleware that records request duration and count.

func (*Registry) MustRegister

func (r *Registry) MustRegister(cs ...prometheus.Collector)

MustRegister registers additional Prometheus collectors.

Jump to

Keyboard shortcuts

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