pgxpoolprometheus

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 3 Imported by: 4

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:

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

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

func NewCollector

func NewCollector(stater Stater, labels map[string]string) *Collector

NewCollector creates a new Collector to collect stats from pgxpool.

func (*Collector) Collect

func (c *Collector) Collect(metrics chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (*Collector) Describe

func (c *Collector) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

type Stater

type Stater interface {
	Stat() *pgxpool.Stat
}

Stater is a provider of the Stat() function. Implemented by pgxpool.Pool.

Jump to

Keyboard shortcuts

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