Skip to content

A Prometheus Collector to gather stats from pgxpool.Stat

License

Notifications You must be signed in to change notification settings

0x00dec0de/pgxpoolprometheus

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

Name Description
pgxpool_acquire_count Cumulative count of successful acquires from the pool.
pgxpool_acquire_duration_ns Total duration of all successful acquires from the pool in nanoseconds.
pgxpool_acquired_conns Number of currently acquired connections in the pool.
pgxpool_canceled_acquire_count Cumulative count of acquires from the pool that were canceled by a context.
pgxpool_constructing_conns Number of conns with construction in progress in the pool.
pgxpool_empty_acquire Cumulative count of successful acquires from the pool that waited for a resource to be released or constructed because the pool was empty.
pgxpool_idle_conns Number of currently idle conns in the pool.
pgxpool_max_conns Maximum size of the pool.
pgxpool_total_conns Total number of resources currently in the pool. The value is the sum of ConstructingConns, AcquiredConns, and IdleConns.

About

A Prometheus Collector to gather stats from pgxpool.Stat

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.5%
  • Shell 0.5%