Skip to content

Commit

Permalink
rename everything to use pgxpool instead of just pgx
Browse files Browse the repository at this point in the history
  • Loading branch information
cmackenzie1 committed Feb 6, 2023
1 parent ca0b3ae commit 672c623
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
panic(err)
}

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

log.Fatalf("Error: %v", http.ListenAndServe(":8080", promhttp.Handler()))
}
Expand Down
4 changes: 2 additions & 2 deletions _example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"net/http"

pgx_prometheus "github.com/cmackenzie1/pgxpool-prometheus"
"github.com/cmackenzie1/pgxpool-prometheus"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -25,7 +25,7 @@ func main() {
}
defer pool.Close()

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

if err := pool.QueryRow(context.Background(), "SELECT 1").Scan(nil); err != nil {
panic(err)
Expand Down
16 changes: 8 additions & 8 deletions collector.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package pgx_prometheus
package pgxpool_prometheus

import (
"github.com/jackc/pgx/v5/pgxpool"
"github.com/prometheus/client_golang/prometheus"
)

// PgxPoolCollector is a Prometheus collector for pgx metrics.
// PgxPoolStatsCollector is a Prometheus collector for pgx metrics.
// It implements the prometheus.Collector interface.
type PgxPoolCollector struct {
type PgxPoolStatsCollector struct {
db *pgxpool.Pool

acquireConns *prometheus.Desc
Expand All @@ -22,16 +22,16 @@ type PgxPoolCollector struct {
maxIdleDestroyCount *prometheus.Desc
}

// NewPgxStatsCollector returns a new pgxCollector.
// 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 NewPgxStatsCollector(db *pgxpool.Pool, dbName string) *PgxPoolCollector {
func NewPgxPoolStatsCollector(db *pgxpool.Pool, dbName string) *PgxPoolStatsCollector {
fqName := func(name string) string {
return prometheus.BuildFQName("pgx", "pool", name)
}
return &PgxPoolCollector{
return &PgxPoolStatsCollector{
db: db,
acquireConns: prometheus.NewDesc(
fqName("acquire_connections"),
Expand Down Expand Up @@ -97,7 +97,7 @@ func NewPgxStatsCollector(db *pgxpool.Pool, dbName string) *PgxPoolCollector {
}

// Describe implements the prometheus.Collector interface.
func (p PgxPoolCollector) Describe(descs chan<- *prometheus.Desc) {
func (p PgxPoolStatsCollector) Describe(descs chan<- *prometheus.Desc) {
descs <- p.acquireConns
descs <- p.canceledAcquireCount
descs <- p.constructingConns
Expand All @@ -111,7 +111,7 @@ func (p PgxPoolCollector) Describe(descs chan<- *prometheus.Desc) {
}

// Collect implements the prometheus.Collector interface.
func (p PgxPoolCollector) Collect(metrics chan<- prometheus.Metric) {
func (p PgxPoolStatsCollector) Collect(metrics chan<- prometheus.Metric) {
stats := p.db.Stat()

metrics <- prometheus.MustNewConstMetric(p.acquireConns, prometheus.GaugeValue, float64(stats.AcquiredConns()))
Expand Down

0 comments on commit 672c623

Please sign in to comment.