metrics

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package metrics provides Prometheus metrics for the tunnel library.

This package implements optional Prometheus metrics export for monitoring tunnel performance and health.

Example

metrics := metrics.NewCollector("go_tunnel")
metrics.Register()

// In your tunnel handler
metrics.IncConnections()
metrics.AddBytesSent(1024)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector holds Prometheus metrics for a tunnel.

func DefaultCollector

func DefaultCollector(namespace string) *Collector

DefaultCollector returns a collector with default configuration.

func NewCollector

func NewCollector(cfg Config) *Collector

NewCollector creates a new metrics collector.

func (*Collector) AddBackpressureYieldTime

func (c *Collector) AddBackpressureYieldTime(seconds float64)

AddBackpressureYieldTime adds to the backpressure yield time counter.

func (*Collector) AddBytesReceived

func (c *Collector) AddBytesReceived(n float64)

AddBytesReceived adds n bytes to the bytes received counter.

func (*Collector) AddBytesSent

func (c *Collector) AddBytesSent(n float64)

AddBytesSent adds n bytes to the bytes sent counter.

func (*Collector) DecActive

func (c *Collector) DecActive()

DecActive decrements the active connections gauge.

func (*Collector) IncActive

func (c *Collector) IncActive()

IncActive increments the active connections gauge.

func (*Collector) IncBackpressurePauses

func (c *Collector) IncBackpressurePauses()

IncBackpressurePauses increments the backpressure pauses counter.

func (*Collector) IncConnections

func (c *Collector) IncConnections()

IncConnections increments the total connections counter.

func (*Collector) IncConnectionsBy

func (c *Collector) IncConnectionsBy(n float64)

IncConnectionsBy increments the total connections counter by n.

func (*Collector) IncErrors

func (c *Collector) IncErrors()

IncErrors increments the errors counter.

func (*Collector) IncErrorsBy

func (c *Collector) IncErrorsBy(n float64)

IncErrorsBy increments the errors counter by n.

func (*Collector) IncPoolClosed

func (c *Collector) IncPoolClosed()

IncPoolClosed increments the pool connections closed counter.

func (*Collector) IncPoolCreated

func (c *Collector) IncPoolCreated()

IncPoolCreated increments the pool connections created counter.

func (*Collector) IncPoolReused

func (c *Collector) IncPoolReused()

IncPoolReused increments the pool connections reused counter.

func (*Collector) ObserveConnectionDuration

func (c *Collector) ObserveConnectionDuration(seconds float64)

ObserveConnectionDuration observes a connection duration.

func (*Collector) ObserveForwardLatency

func (c *Collector) ObserveForwardLatency(seconds float64)

ObserveForwardLatency observes a forward latency.

func (*Collector) ObservePoolWait

func (c *Collector) ObservePoolWait(seconds float64)

ObservePoolWait observes a pool wait duration.

func (*Collector) SetActive

func (c *Collector) SetActive(n float64)

SetActive sets the active connections gauge to n.

func (*Collector) SetPoolActive

func (c *Collector) SetPoolActive(n float64)

SetPoolActive sets the active pool connections.

type Config

type Config struct {
	// Namespace is the prefix for all metrics.
	Namespace string

	// Subsystem is an optional subsystem prefix.
	Subsystem string

	// Registry is the Prometheus registerer to use.
	// If nil, the default registerer is used.
	Registry prometheus.Registerer

	// EnableConnectionDuration enables connection duration histogram.
	EnableConnectionDuration bool

	// EnableForwardLatency enables forward latency histogram.
	EnableForwardLatency bool

	// EnablePoolMetrics enables connection pool metrics.
	EnablePoolMetrics bool

	// EnableBackpressureMetrics enables backpressure metrics.
	EnableBackpressureMetrics bool
}

Config holds configuration for the metrics collector.

Jump to

Keyboard shortcuts

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