pgxprom

package module
v0.0.0-...-8a1d941 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 8 Imported by: 0

README

pgxprom

A prometheus adapter for pgx

Go Reference

Getting Started

You can use these examples to get started.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var TraceBatchKey = &ContextKey{
	name: reflect.TypeOf(TraceBatchData{}).PkgPath(),
}

TraceBatchKey represents the context key of the data.

View Source
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 PoolCollector

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

PoolCollector 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.NewPoolCollector()
	// register the pool
	collector.Add(pool)
	// register the collector
	if err := prometheus.Register(collector); err != nil {
		panic(err)
	}
}
Output:

func NewPoolCollector

func NewPoolCollector() *PoolCollector

NewPoolCollector returns a new collector.

func (*PoolCollector) Add

func (p *PoolCollector) Add(pool *pgxpool.Pool)

Add append the pool the collector

func (*PoolCollector) Collect

func (p *PoolCollector) Collect(metrics chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (*PoolCollector) Describe

func (p *PoolCollector) Describe(descs chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

func (*PoolCollector) Remove

func (p *PoolCollector) Remove(pool *pgxpool.Pool)

Remove removes the pool from the collector

type QueryCollector

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

QueryCollector is a Prometheus query collector for pgx metrics.

func NewQueryCollector

func NewQueryCollector() *QueryCollector

NewQueryCollector creates a new Tracer.

func (*QueryCollector) Collect

func (q *QueryCollector) Collect(metrics chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*QueryCollector) Describe

func (q *QueryCollector) Describe(descs chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*QueryCollector) TraceBatchEnd

func (q *QueryCollector) TraceBatchEnd(ctx context.Context, conn *pgx.Conn, args pgx.TraceBatchEndData)

TraceBatchEnd implements pgx.BatchTracer.

func (*QueryCollector) TraceBatchQuery

func (q *QueryCollector) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchQueryData)

TraceBatchQuery implements pgx.BatchTracer.

func (*QueryCollector) TraceBatchStart

func (q *QueryCollector) TraceBatchStart(ctx context.Context, conn *pgx.Conn, args pgx.TraceBatchStartData) context.Context

TraceBatchStart implements pgx.BatchTracer.

func (*QueryCollector) TraceQueryEnd

func (q *QueryCollector) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, args pgx.TraceQueryEndData)

TraceQueryEnd implements pgx.QueryTracer.

func (*QueryCollector) TraceQueryStart

func (q *QueryCollector) TraceQueryStart(ctx context.Context, conn *pgx.Conn, args pgx.TraceQueryStartData) context.Context

TraceQueryStart implements pgx.QueryTracer.

type TraceBatchData

type TraceBatchData struct {
	StartedAt time.Time
	Batch     *pgx.Batch
}

TraceBatchData represents a batch data

type TraceQueryData

type TraceQueryData struct {
	StartedAt time.Time
	SQL       string
	Args      []any
}

TraceQueryData represents a query data

Jump to

Keyboard shortcuts

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