Lightweight SQL instrumentation for Prometheus.
go get github.com/alexkhm32/promsqlpromsql decorates the standard library's database/sql to record execution time and expose Prometheus metrics. You can open a connection with promsql.Open (by driver name + DSN) or promsql.OpenDB (by driver.Connector).
Open using a driver name and DSN:
db, err := promsql.Open("<your driver>", dataSourceName)
if err != nil {
return fmt.Errorf("open database connection: %w", err)
}Open using a connector:
db := promsql.OpenDB(
connector /* connector of your driver */,
promsql.WithRegisterer(registry),
)You can find a simple example of how to use this package in example/simple.
db_client_operation_duration_seconds- duration of database operations (seconds). Tracks SQL execution time, including network overhead and server processing.- Labels:
db_query_text- text of the executed SQL query.
- Labels:
WithRegisterer- provide a customprometheus.Registererinstead of the defaultprometheus.DefaultRegisterer.
See LICENSE.