observe

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package observe provides lightweight, lock-free metrics collection for celeris servers.

Use Collector.Snapshot to retrieve a point-in-time Snapshot containing request counts, error rates, latency histogram, active connections, and engine-level metrics. All recording methods are safe for concurrent use.

For Prometheus and debug endpoint integration, see the github.com/goceleris/middlewares module.

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 aggregates request metrics using lock-free counters. A Collector is safe for concurrent use by multiple goroutines.

func NewCollector

func NewCollector() *Collector

NewCollector creates a new Collector.

func (*Collector) ConnClosed

func (c *Collector) ConnClosed()

ConnClosed decrements the active connection gauge.

func (*Collector) ConnOpened

func (c *Collector) ConnOpened()

ConnOpened increments the active connection gauge.

func (*Collector) RecordError

func (c *Collector) RecordError()

RecordError increments the error counter.

Note: RecordRequest automatically counts responses with status >= 500 as errors. Use RecordError only for errors that do not result in an HTTP response (e.g., connection-level failures).

func (*Collector) RecordRequest

func (c *Collector) RecordRequest(duration time.Duration, status int)

RecordRequest increments the request counter and records the latency in the appropriate histogram bucket. Status codes >= 500 also increment the error counter.

func (*Collector) RecordSwitch

func (c *Collector) RecordSwitch()

RecordSwitch increments the engine switch counter.

func (*Collector) SetEngineMetricsFn

func (c *Collector) SetEngineMetricsFn(fn func() EngineMetrics)

SetEngineMetricsFn registers a function that returns current engine metrics.

func (*Collector) Snapshot

func (c *Collector) Snapshot() Snapshot

Snapshot returns a point-in-time copy of all collected metrics.

type EngineMetrics

type EngineMetrics = engine.EngineMetrics

EngineMetrics is a point-in-time snapshot of engine-level performance counters.

type Snapshot

type Snapshot struct {
	// RequestsTotal is the cumulative number of handled requests.
	RequestsTotal uint64
	// ErrorsTotal is the cumulative number of requests that returned HTTP 5xx.
	ErrorsTotal uint64
	// ActiveConns is the number of currently open connections.
	ActiveConns int64
	// EngineSwitches counts how many times the adaptive engine changed strategies.
	EngineSwitches uint64
	// LatencyBuckets holds request counts per latency histogram bucket.
	LatencyBuckets []uint64
	// BucketBounds are the upper-bound thresholds (in seconds) for each bucket.
	BucketBounds []float64
	// EngineMetrics contains the underlying engine's own performance counters.
	EngineMetrics EngineMetrics
}

Snapshot is a point-in-time copy of all collected metrics. All fields are read-only values captured at the moment Collector.Snapshot was called.

Jump to

Keyboard shortcuts

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