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 ¶
- type Collector
- func (c *Collector) ConnClosed()
- func (c *Collector) ConnOpened()
- func (c *Collector) RecordError()
- func (c *Collector) RecordRequest(duration time.Duration, status int)
- func (c *Collector) RecordSwitch()
- func (c *Collector) SetEngineMetricsFn(fn func() EngineMetrics)
- func (c *Collector) Snapshot() Snapshot
- type EngineMetrics
- type Snapshot
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 (*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 ¶
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.
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.