pgxpool_prometheus

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 2 Imported by: 0

README

pgxpool-prometheus

Go Reference Go

A pgx Prometheus metrics collector for Go applications using pgxpool.

Installation

go get github.com/cmackenzie1/pgxpool-prometheus

Usage

Please see the example directory for a complete example.

package main

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

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

func main() {
	// Create a pgxpool.Config
	config, err := pgxpool.ParseConfig("postgres://postgres:password@localhost:5432/?sslmode=disable")
	if err != nil {
		panic(err)
	}

	// Create a pgxpool.Pool
	pool, err := pgxpool.NewWithConfig(context.Background(), config)
	if err != nil {
		panic(err)
	}

	prometheus.MustRegister(pgxpool_prometheus.NewPgxPoolStatsCollector(pool, "database"))

	log.Fatalf("Error: %v", http.ListenAndServe(":8080", promhttp.Handler()))
}

Exported Metrics

Metric Type Description
pgx_pool_acquire_connections Gauge Number of connections currently in the process of being acquired
pgx_pool_canceled_acquire_count Counter Number of times a connection acquire was canceled
pgx_pool_constructing_connections Gauge Number of connections currently in the process of being constructed
pgx_pool_empty_acquire_count Counter Number of times a connection acquire was canceled
pgx_pool_idle_connections Gauge Number of idle connections in the pool
pgx_pool_max_connections Gauge Maximum number of connections allowed in the pool
pgx_pool_max_idle_destroy_count Counter Number of connections destroyed due to MaxIdleTime
pgx_pool_max_lifetime_destroy_count Counter Number of connections destroyed due to MaxLifetime
pgx_pool_new_connections_count Counter Number of new connections created
pgx_pool_total_connections Gauge Total number of connections in the pool

License

pgx-prometheus is licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PgxPoolStatsCollector added in v0.2.0

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

PgxPoolStatsCollector is a Prometheus collector for pgx metrics. It implements the prometheus.Collector interface.

func NewPgxPoolStatsCollector added in v0.2.0

func NewPgxPoolStatsCollector(db *pgxpool.Pool, dbName string) *PgxPoolStatsCollector

NewPgxPoolStatsCollector returns a new pgxCollector. The dbName parameter is used to set the "db" label on the metrics. The db parameter is the pgxpool.Pool to collect metrics from. The db parameter must not be nil. The dbName parameter must not be empty.

func (PgxPoolStatsCollector) Collect added in v0.2.0

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

Collect implements the prometheus.Collector interface.

func (PgxPoolStatsCollector) Describe added in v0.2.0

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

Describe implements the prometheus.Collector interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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