tsdb

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Overview

Package tsdb wraps the Prometheus TSDB with rule-derived retention, a size ceiling, and pressure shrinking.

Index

Constants

View Source
const (
	DefaultBlockDuration   = 30 * time.Minute
	DefaultWALSegmentBytes = 8 << 20
)

Defaults.

View Source
const HardCeiling = 6 * time.Hour

HardCeiling bounds retention regardless of what rules request.

Variables

This section is empty.

Functions

func ClampRetention

func ClampRetention(r time.Duration) time.Duration

ClampRetention applies the hard ceiling.

Types

type DB

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

DB is an open local TSDB. It implements storage.Queryable and storage.Appendable.

func Open

func Open(dir string, o Options) (*DB, error)

Open opens or creates the TSDB in dir with a write-ahead log.

func (*DB) Appender

func (d *DB) Appender(ctx context.Context) storage.Appender

Appender implements storage.Appendable.

func (*DB) Close

func (d *DB) Close() error

Close flushes and closes the store.

func (*DB) Querier

func (d *DB) Querier(mint, maxt int64) (storage.Querier, error)

Querier implements storage.Queryable.

func (*DB) Relax

func (d *DB) Relax() error

Relax removes a pressure limit installed by Shrink.

func (*DB) Retention

func (d *DB) Retention() time.Duration

Retention returns the effective retention.

func (*DB) SetMaxBytes

func (d *DB) SetMaxBytes(n int64) error

SetMaxBytes changes the configured size bound; zero disables it.

func (*DB) SetRetention

func (d *DB) SetRetention(r time.Duration) (time.Duration, error)

SetRetention applies a rule-derived retention (clamped) and returns the effective value.

func (*DB) Shrink

func (d *DB) Shrink(ctx context.Context, target int64) (freed int64, err error)

Shrink drops the oldest data toward target and keeps target as a size limit until Relax.

func (*DB) Size

func (d *DB) Size() int64

Size is the on-disk footprint: blocks, WAL, and head chunks.

func (*DB) Stats

func (d *DB) Stats() Stats

Stats returns current counts and settings.

type Options

type Options struct {
	// Retention is derived from rules; zero or anything above HardCeiling means HardCeiling.
	Retention time.Duration
	// MaxBytes bounds blocks, WAL, and head chunks together; zero disables the size bound.
	MaxBytes int64
	// BlockDuration is the head compaction granularity, which is also the retention granularity.
	BlockDuration time.Duration
	// WALSegmentBytes must be a multiple of 32 KiB.
	WALSegmentBytes int
	Logger          *slog.Logger
}

Options configures Open.

type Stats

type Stats struct {
	Series    uint64
	Bytes     int64
	Blocks    int
	MinTime   time.Time
	MaxTime   time.Time
	Retention time.Duration
	MaxBytes  int64
	Limit     int64
}

Stats describes the store.

Jump to

Keyboard shortcuts

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