Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose connection pool stats #1474

Merged
merged 1 commit into from
Sep 5, 2024
Merged

Conversation

turip
Copy link
Contributor

@turip turip commented Sep 4, 2024

Overview

This patch exposes the connection pool statistics via opentelemetry, so that we see for all the workers the distribution of idle/acquired etc. connections.

Example metrics:

# HELP pgxpool_acquire_count_total The cumulative count of successful acquires from the pool.
# TYPE pgxpool_acquire_count_total counter
pgxpool_acquire_count_total{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 4
# HELP pgxpool_acquire_duration_avg_milliseconds The average duration of all successful acquires from the pool in ms.
# TYPE pgxpool_acquire_duration_avg_milliseconds gauge
pgxpool_acquire_duration_avg_milliseconds{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 2
# HELP pgxpool_acquire_duration_milliseconds The total duration of all successful acquires from the pool in ms.
# TYPE pgxpool_acquire_duration_milliseconds gauge
pgxpool_acquire_duration_milliseconds{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 10
# HELP pgxpool_acquired_conns The number of currently acquired connections in the pool.
# TYPE pgxpool_acquired_conns gauge
pgxpool_acquired_conns{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 0
# HELP pgxpool_canceled_acquire_count_total The cumulative count of acquires from the pool that were canceled by a context.
# TYPE pgxpool_canceled_acquire_count_total counter
pgxpool_canceled_acquire_count_total{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 0
# HELP pgxpool_constructing_conns The number of conns with construction in progress in the pool.
# TYPE pgxpool_constructing_conns gauge
pgxpool_constructing_conns{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 0
# HELP pgxpool_empty_acquire_count_total The cumulative count of successful acquires from the pool that waited for a resource to be released or constructed because the pool was empty.
# TYPE pgxpool_empty_acquire_count_total counter
pgxpool_empty_acquire_count_total{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 1
# HELP pgxpool_idle_conns The number of currently idle conns in the pool.
# TYPE pgxpool_idle_conns gauge
pgxpool_idle_conns{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 1
# HELP pgxpool_max_conns The maximum size of the pool.
# TYPE pgxpool_max_conns gauge
pgxpool_max_conns{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 16
# HELP pgxpool_max_idle_destroy_count_total The cumulative count of connections closed due to reaching their maximum idle time (MaxConnIdleTime).
# TYPE pgxpool_max_idle_destroy_count_total counter
pgxpool_max_idle_destroy_count_total{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 0
# HELP pgxpool_max_lifetime_destroy_count_total The cumulative count of connections closed due to reaching their maximum lifetime (MaxConnLifetime).
# TYPE pgxpool_max_lifetime_destroy_count_total counter
pgxpool_max_lifetime_destroy_count_total{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 0
# HELP pgxpool_new_conns_count_total The cumulative count of new connections opened.
# TYPE pgxpool_new_conns_count_total counter
pgxpool_new_conns_count_total{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 1
# HELP pgxpool_total_conns The total number of resources currently in the pool. The value is the sum of ConstructingConns, AcquiredConns, and IdleConns.
# TYPE pgxpool_total_conns gauge
pgxpool_total_conns{otel_scope_name="openmeter.io/backend",otel_scope_version=""} 1

Notes for reviewer

@sagikazarmark if this works well enough we can split this into a separate package.

@turip turip added the release-note/feature Release note: Exciting New Features label Sep 4, 2024
@turip turip marked this pull request as ready for review September 4, 2024 14:57
@turip turip merged commit 5ba5524 into main Sep 5, 2024
18 of 19 checks passed
@turip turip deleted the expose-connection-pool-stats branch September 5, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants