Documentation ¶
Index ¶
- Variables
- type ContextKey
- type PoolStatsCollector
- type TraceBatchData
- type TraceQueryData
- type Tracer
- func (q *Tracer) TraceBatchEnd(ctx context.Context, conn *pgx.Conn, end pgx.TraceBatchEndData)
- func (q *Tracer) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchQueryData)
- func (q *Tracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, start pgx.TraceBatchStartData) context.Context
- func (q *Tracer) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, end pgx.TraceQueryEndData)
- func (q *Tracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, start pgx.TraceQueryStartData) context.Context
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Request is the total number of database requests. RequestTotal *prometheus.CounterVec // ErrorsTotal is the total number of database request errors. ErrorsTotal *prometheus.CounterVec // Duration is the time taken to complete a database request and process the response. Duration *prometheus.HistogramVec )
var TraceBatchKey = &ContextKey{ name: reflect.TypeOf(TraceBatchData{}).PkgPath(), }
TraceBatchKey represents the context key of the data.
var TraceQueryKey = &ContextKey{ name: reflect.TypeOf(TraceQueryData{}).PkgPath(), }
TraceQueryKey represents the context key of the data.
Functions ¶
This section is empty.
Types ¶
type ContextKey ¶
type ContextKey struct {
// contains filtered or unexported fields
}
ContextKey represents a context key.
func (*ContextKey) String ¶
func (k *ContextKey) String() string
String returns the context key as a string.
type PoolStatsCollector ¶
type PoolStatsCollector struct {
// contains filtered or unexported fields
}
PoolStatsCollector is a Prometheus pool collector for pgx metrics.
Example ¶
package main import ( "context" "os" "github.com/jackc/pgx/v5/pgxpool" "github.com/pgx-contrib/pgxprom" "github.com/prometheus/client_golang/prometheus" ) func main() { config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL")) if err != nil { panic(err) } pool, err := pgxpool.NewWithConfig(context.TODO(), config) if err != nil { panic(err) } collector := pgxprom.NewPoolStatsCollector() // register the pool collector.Register(pool) // register the collector if err := prometheus.Register(collector); err != nil { panic(err) } }
Output:
func NewPoolStatsCollector ¶
func NewPoolStatsCollector() *PoolStatsCollector
NewPoolStatsCollector returns a new collector.
func (*PoolStatsCollector) Collect ¶
func (p *PoolStatsCollector) Collect(metrics chan<- prometheus.Metric)
Collect implements the prometheus.Collector interface.
func (*PoolStatsCollector) Describe ¶
func (p *PoolStatsCollector) Describe(descs chan<- *prometheus.Desc)
Describe implements the prometheus.Collector interface.
func (*PoolStatsCollector) Register ¶
func (p *PoolStatsCollector) Register(pool *pgxpool.Pool)
Register append the pool the collector
func (*PoolStatsCollector) Unregister ¶
func (p *PoolStatsCollector) Unregister(pool *pgxpool.Pool)
Unregister removes the pool from the collector
type TraceBatchData ¶
TraceBatchData represents a batch data
type TraceQueryData ¶
TraceQueryData represents a query data
type Tracer ¶
type Tracer struct{}
Tracer is a Prometheus query collector for pgx metrics.
Example ¶
package main import ( "context" "os" "github.com/jackc/pgx/v5/pgxpool" "github.com/pgx-contrib/pgxprom" ) var count int func main() { config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL")) if err != nil { panic(err) } config.ConnConfig.Tracer = &pgxprom.Tracer{} conn, err := pgxpool.NewWithConfig(context.TODO(), config) if err != nil { panic(err) } row := conn.QueryRow(context.TODO(), "SELECT 1") if err := row.Scan(&count); err != nil { panic(err) } }
Output:
func (*Tracer) TraceBatchEnd ¶
TraceBatchEnd implements pgx.BatchTracer.
func (*Tracer) TraceBatchQuery ¶
TraceBatchQuery implements pgx.BatchTracer.
func (*Tracer) TraceBatchStart ¶
func (q *Tracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, start pgx.TraceBatchStartData) context.Context
TraceBatchStart implements pgx.BatchTracer.
func (*Tracer) TraceQueryEnd ¶
TraceQueryEnd implements pgx.QueryTracer.