db_metrics

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 8 Imported by: ? 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

Index

Constants

This section is empty.

Variables

View Source
var ConnectionsInUseDesc = prometheus.NewDesc(
	metricsSubsystem+"_connections_in_use",
	"Number of database connections currently in use.",
	nil,
	prometheus.Labels{labelComponent: componentValue, labelVersion: api.Version},
)

ConnectionsInUseDesc is the descriptor for the connections_in_use gauge.

View Source
var ConnectionsOpenDesc = prometheus.NewDesc(
	metricsSubsystem+"_connections_open",
	"Number of open database connections.",
	nil,
	prometheus.Labels{labelComponent: componentValue, labelVersion: api.Version},
)

ConnectionsOpenDesc is the descriptor for the connections_open gauge.

View Source
var ErrorsMetric = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Subsystem: metricsSubsystem,
		Name:      "errors_total",
		Help:      "Total number of database query errors.",
	},
	[]string{labelOperation, labelErrorType, labelComponent, labelVersion},
)

ErrorsMetric is a counter of database query errors.

View Source
var QueryDurationMetric = prometheus.NewHistogramVec(
	prometheus.HistogramOpts{
		Subsystem: metricsSubsystem,
		Name:      "query_duration_seconds",
		Help:      "Duration of database queries in seconds.",
		Buckets:   queryDurationBuckets,
	},
	[]string{labelOperation, labelTable, labelComponent, labelVersion},
)

QueryDurationMetric is a histogram of database query durations in seconds.

Functions

func RegisterMetrics

func RegisterMetrics()

RegisterMetrics registers the database metrics with Prometheus. It is safe to call multiple times; registration happens only once.

func RegisterPlugin

func RegisterPlugin(db *gorm.DB) error

RegisterPlugin registers the metrics GORM callbacks on the provided *gorm.DB. It adds before/after callbacks for create, query, update, delete, and raw operations.

func RegisterPoolCollector

func RegisterPoolCollector(db *sql.DB) error

RegisterPoolCollector creates and registers a new PoolCollector for the given database.

func ResetMetrics

func ResetMetrics()

ResetMetrics resets all resettable database metrics.

Types

type PoolCollector

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

PoolCollector implements the prometheus.Collector interface to report database connection pool statistics.

func NewPoolCollector

func NewPoolCollector(db *sql.DB) *PoolCollector

NewPoolCollector creates a new PoolCollector for the given database connection.

func (*PoolCollector) Collect

func (c *PoolCollector) Collect(ch chan<- prometheus.Metric)

Collect reads the current connection pool stats and sends them as metrics.

func (*PoolCollector) Describe

func (c *PoolCollector) Describe(ch chan<- *prometheus.Desc)

Describe sends the descriptors for the connection pool metrics.

Jump to

Keyboard shortcuts

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