db_metrics

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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