Categorygithub.com/IBM/pgxpoolprometheus
modulepackage
1.1.1
Repository: https://github.com/ibm/pgxpoolprometheus.git
Documentation: pkg.go.dev

# README

Build Status Release GitHub go.mod Go version License

Prometheus Collector for PGX Pool

This is a Prometheus Collector for PGX Pool.

Example Usage

package main

import (
	"context"
	"log"
	"net/http"
	"os"

	"github.com/jackc/pgx/v5/pgxpool"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"

	"github.com/IBM/pgxpoolprometheus"
)

func main() {
	pool, err := pgxpool.Connect(context.Background(), os.Getenv("DATABASE_URL"))
	if err != nil {
		log.Fatal(err)
	}

	collector := pgxpoolprometheus.NewCollector(pool, map[string]string{"db_name": "my_db"})
	prometheus.MustRegister(collector)

	http.Handle("/metrics", promhttp.Handler())
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Metrics Collected

This collector provides metrics for all the stats produced by pgxpool.Stat all prefixed with pgxpool:

NameDescription
pgxpool_acquire_countCumulative count of successful acquires from the pool.
pgxpool_acquire_duration_nsTotal duration of all successful acquires from the pool in nanoseconds.
pgxpool_acquired_connsNumber of currently acquired connections in the pool.
pgxpool_canceled_acquire_countCumulative count of acquires from the pool that were canceled by a context.
pgxpool_constructing_connsNumber of conns with construction in progress in the pool.
pgxpool_empty_acquireCumulative count of successful acquires from the pool that waited for a resource to be released or constructed because the pool was empty.
pgxpool_idle_connsNumber of currently idle conns in the pool.
pgxpool_max_connsMaximum size of the pool.
pgxpool_total_connsTotal number of resources currently in the pool. The value is the sum of ConstructingConns, AcquiredConns, and IdleConns.

# Functions

NewCollector creates a new Collector to collect stats from pgxpool.

# Structs

Collector is a prometheus.Collector that will collect the nine statistics produced by pgxpool.Stat.

# Interfaces

Stater is a provider of the Stat() function.