Documentation
¶
Overview ¶
Package tsdb provides an in-memory ring buffer for per-metric sliding windows with pre-computed aggregates. It accelerates dashboard queries for recent data so they never need to hit the relational DB.
Index ¶
- type Aggregator
- func (a *Aggregator) BucketCount() int
- func (a *Aggregator) DroppedBatches() int64
- func (a *Aggregator) Ingest(m RawMetric)
- func (a *Aggregator) SetCardinalityLimit(max int, onOverflow func())
- func (a *Aggregator) SetMetrics(onIngest, onDropped func())
- func (a *Aggregator) SetRingBuffer(rb *RingBuffer)
- func (a *Aggregator) Start(ctx context.Context)
- func (a *Aggregator) Stop()
- type MetricRing
- type RawMetric
- type RingBuffer
- type WindowAgg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator manages in-memory tumbling windows for metrics.
func NewAggregator ¶
func NewAggregator(repo *storage.Repository, windowSize time.Duration) *Aggregator
NewAggregator creates a new TSDB aggregator.
func (*Aggregator) BucketCount ¶
func (a *Aggregator) BucketCount() int
BucketCount returns the current number of in-memory buckets (for metrics/health).
func (*Aggregator) DroppedBatches ¶
func (a *Aggregator) DroppedBatches() int64
DroppedBatches returns the total number of batches dropped due to a full flush channel.
func (*Aggregator) Ingest ¶
func (a *Aggregator) Ingest(m RawMetric)
Ingest adds a raw metric point to the current aggregator window.
func (*Aggregator) SetCardinalityLimit ¶
func (a *Aggregator) SetCardinalityLimit(max int, onOverflow func())
SetCardinalityLimit configures the maximum number of distinct metric series. When exceeded, new series are routed to an overflow bucket and onOverflow is called.
func (*Aggregator) SetMetrics ¶
func (a *Aggregator) SetMetrics(onIngest, onDropped func())
SetMetrics wires Prometheus metric callbacks.
func (*Aggregator) SetRingBuffer ¶
func (a *Aggregator) SetRingBuffer(rb *RingBuffer)
SetRingBuffer attaches a RingBuffer that receives every ingested data point.
func (*Aggregator) Start ¶
func (a *Aggregator) Start(ctx context.Context)
Start begins the aggregation background processes.
type MetricRing ¶
type MetricRing struct {
// contains filtered or unexported fields
}
MetricRing is a fixed-size circular buffer for a single metric+service key. Each slot represents one windowDuration-wide time bucket.
func (*MetricRing) Record ¶
func (r *MetricRing) Record(value float64, at time.Time)
Record adds a new data point, advancing the window if necessary.
func (*MetricRing) Windows ¶
func (r *MetricRing) Windows(n int) []WindowAgg
Windows returns up to `n` most-recent completed window aggregates.
type RawMetric ¶
type RawMetric struct {
Name string
ServiceName string
Value float64
Timestamp time.Time
Attributes map[string]interface{}
}
RawMetric represents an incoming single metric data point before aggregation.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer manages per-metric ring buffers, keyed by "service|metric".
func NewRingBuffer ¶
func NewRingBuffer(slots int, windowDur time.Duration) *RingBuffer
NewRingBuffer creates a RingBuffer. slots × windowDur = total retention (e.g. 120 × 30s = 1 hour).
func (*RingBuffer) AllKeys ¶
func (rb *RingBuffer) AllKeys() []string
AllKeys returns all registered metric+service keys.
func (*RingBuffer) MetricCount ¶
func (rb *RingBuffer) MetricCount() int
MetricCount returns the number of distinct metric series tracked.
func (*RingBuffer) QueryRecent ¶
func (rb *RingBuffer) QueryRecent(metricName, serviceName string, windowCount int) []WindowAgg
QueryRecent returns aggregated windows for the given metric+service. Pass an empty serviceName to query across all services (returns first match).