Documentation
¶
Index ¶
Constants ¶
const Namespace = "tr_tavern"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CounterSmoother ¶
type CounterSmoother struct {
Alpha float64
// contains filtered or unexported fields
}
CounterSmoother computes an exponentially-weighted moving average (EWMA) of the per-tick delta of a monotonically-increasing counter.
It is safe for concurrent use.
Alpha controls the smoothing factor: Alpha=0 means the smoothed value never changes (frozen at the first non-zero delta), Alpha=1 means no smoothing at all (raw delta returned as-is). Typical values for QPS smoothing are 0.2–0.5.
func NewCounterSmoother ¶
func NewCounterSmoother(alpha float64) *CounterSmoother
NewCounterSmoother returns an initialized CounterSmoother. alpha is clamped to [0, 1].
func (*CounterSmoother) Reset ¶
func (s *CounterSmoother) Reset()
Reset discards all internal state so the next call to Update behaves as if the smoother were newly created. Alpha is preserved.
func (*CounterSmoother) Update ¶
func (s *CounterSmoother) Update(raw float64) float64
Update receives the current raw cumulative counter value and returns the smoothed per-tick delta.
On the first call it records the baseline and returns 0. When the raw value does not increase (delta <= 0) the smoothed value decays exponentially towards zero — this handles counter resets and idle periods gracefully.
NaN and Inf inputs are silently ignored (the current smoothed value is returned unchanged and internal state is not corrupted).
type RequestsCounter ¶
type RequestsCounter struct {
// contains filtered or unexported fields
}
RequestsCounter tracks HTTP request counts by protocol and response code. It implements prometheus.Collector so Prometheus can scrape per-(protocol,code) counters at scrape interval, while real-time consumers call Snapshot() to get code-aggregated totals without walking the full metric registry.
func NewRequestsCounter ¶
func NewRequestsCounter(opts prometheus.Opts, labelNames []string) *RequestsCounter
NewRequestsCounter creates a RequestsCounter and registers it with the given registerer. The produced metric name is tr_tavern_requests_code_total with labels "protocol" and "code", matching the previous CounterVec-based naming.
func (*RequestsCounter) Collect ¶
func (c *RequestsCounter) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector. Each label combination is emitted as a separate Counter metric so the output matches the previous CounterVec.
func (*RequestsCounter) Describe ¶
func (c *RequestsCounter) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
func (*RequestsCounter) Inc ¶
func (c *RequestsCounter) Inc(protocol, code string)
Inc increments the counter for the given protocol and status code.
func (*RequestsCounter) Seed ¶
func (c *RequestsCounter) Seed(protocol, code string)
Seed ensures the counter has a zero-valued entry for the given label pair, so it appears in /metrics output even before any real increment happens.
func (*RequestsCounter) Snapshot ¶
func (c *RequestsCounter) Snapshot() map[string]float64
Snapshot returns the cumulative count aggregated by status code across all protocols. This is the fast path for real-time consumers (e.g. QS plugin) that need per-second reads without triggering a full Gather.