dbstats

package
v1.5.12 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dbstats samples engine statistics by running a read only script inside each database container.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResourceID

func ResourceID(name string) string

ResourceID is the telemetry resource id for a database.

Types

type Collector

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

Collector samples every running Postgres database.

func New

func New(src Source, ex dbaccess.Exec, out Writer, cfg func() Config, every func() time.Duration, log *slog.Logger) *Collector

New builds a Collector; cfg and every are read before each tick so saved settings apply live.

func (*Collector) CollectOnce

func (c *Collector) CollectOnce(ctx context.Context)

CollectOnce samples each running Postgres database with a small worker pool and a per tick budget.

func (*Collector) Run

func (c *Collector) Run(ctx context.Context)

Run samples until ctx ends.

func (*Collector) Status

func (c *Collector) Status() map[string]Status

Status returns the last outcome per database name.

type Config

type Config struct {
	// Timeout bounds one script, both inside psql (statement_timeout) and on the exec.
	Timeout time.Duration
	// MaxDatabases caps per-database rows and size series.
	MaxDatabases int
	// MaxOutputBytes caps the script output read back; 0 derives it from MaxDatabases.
	MaxOutputBytes int64
}

Config carries limits the caller reads from settings before every tick.

type Source

type Source interface {
	RunningDatabases(ctx context.Context) ([]Target, error)
}

Source lists databases that are running now on this node; stopped ones are simply absent.

type Status

type Status struct {
	LastOK    time.Time
	LastError string
	LastErrAt time.Time
}

Status is the last sample outcome for one database.

type Target

type Target struct {
	Name        string
	Engine      string
	ContainerID string
}

Target is one running database to sample.

type Writer

type Writer interface {
	WriteSamples(ctx context.Context, samples []telemetry.Sample) error
}

Writer is the telemetry store surface the collector needs.

Jump to

Keyboard shortcuts

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