dbstats

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadDB    = errors.New("db is nil")
	ErrDBExists = errors.New("db already exists")
)

Functions

func NewContext

func NewContext(ctx context.Context, ex *Exporter) context.Context

NewContext returns a copy of the parent context and associates it with an Exporter.

Types

type Exporter

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

Exporter exports sql.DBStats as Prometheus metrics.

func FromContext

func FromContext(ctx context.Context) (ex *Exporter, ok bool)

FromContext returns the Exporter bound to the context, if any.

func NewExporter

func NewExporter(opts *Opts, labelNames []string) *Exporter

func (*Exporter) MustBind

func (e *Exporter) MustBind(db *sql.DB, labelValues ...string)

func (*Exporter) Start

func (e *Exporter) Start()

func (*Exporter) Stop

func (e *Exporter) Stop()

type Metrics

type Metrics struct {
	MaxOpenConnections *prometheus.GaugeVec // Maximum number of open connections to the database.

	// Pool Status
	OpenConnections *prometheus.GaugeVec // The number of established connections both in use and idle.
	InUse           *prometheus.GaugeVec // The number of connections currently in use.
	Idle            *prometheus.GaugeVec // The number of idle connections.

	// Counters
	WaitCount         *metric.SettableCounterVec // The total number of connections waited for.
	WaitDuration      *metric.SettableCounterVec // The total time (in seconds) blocked waiting for a new connection.
	MaxIdleClosed     *metric.SettableCounterVec // The total number of connections closed due to SetMaxIdleConns.
	MaxLifetimeClosed *metric.SettableCounterVec // The total number of connections closed due to SetConnMaxLifetime.
}

Metrics for sql.DBStats.

type Opts

type Opts struct {
	Namespace string
	Subsystem string

	UpdateInterval time.Duration // How often we fetch and update the DBStats.
}

Jump to

Keyboard shortcuts

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