Skip to content

alexkhm32/promsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promsql

Lightweight SQL instrumentation for Prometheus.

⚠️ Warning: This project is a Proof of Concept.

Install

go get github.com/alexkhm32/promsql

Usage

promsql 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),
)

Examples

You can find a simple example of how to use this package in example/simple.

Metric Instruments

  • 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.

Options

  • WithRegisterer - provide a custom prometheus.Registerer instead of the default prometheus.DefaultRegisterer.

License

See LICENSE.

About

PoC of SQL instrumentation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages