PgBouncer MonitoringUse This InfluxDB Integration for Free
PgBouncer is an open-source connection pooling tool for PostgreSQL. By default, PostgreSQL has a fairly resource-heavy way of handling incoming database connections, creating a new process for each connection. For some use cases this is fine, but in situations where connections are being rapidly created and dropped, it is inefficient.
PgBouncer works by maintaining a pool of connections for each unique user and database pair. When new incoming client requests come in, these pre-made connections are used to handle the request. Once the client disconnects, the database connection is returned back to the pool where it can later be used by a new incoming connection. This saves server resources on the expensive process of creating and initializing TCP connections because each of these connections are created once and then reused by multiple users.
Why use a Telegraf plugin for PgBouncer?
The Telegraf plugin for PgBouncer allows you to easily collect and store valuable metrics from your PgBouncer instance for long-term storage and analysis. Telegraf has over 40 different output plugins but works particularly well with InfluxDB. By outputting your PgBouncer metrics to InfluxDB cloud, you can also set alerts and notifications based on user-defined thresholds.
How to monitor PgBouncer using the Telegraf plugin
Setting up the PgBouncer Telegraf Input Plugin is easy and requires only a few lines of configuration. The only required configuration value is the address of the database as either a PostgreSQL connection string or URL matching like the following:
PostgreSQL connection string
host=/run/postgresql port=6432 user=telegraf database=pgbouncer
Here is a full configuration file example setup:
[[inputs.pgbouncer]] ## specify address via a url matching: ## postgres://[pqgotest[:password]]@host:port[/dbname]\ ## ?sslmode=[disable|verify-ca|verify-full] ## or a simple string: ## host=localhost port=5432 user=pqgotest password=... sslmode=... dbname=app_production ## ## All connection parameters are optional. ## address = "host=localhost user=pgbouncer sslmode=disable"
Key PgBouncer metrics to use for monitoring
The PgBouncer Telegraf Input Plugin provides access to a number of different metrics related to the PgBouncer instance itself, metrics for each connection pool, and aggregate metrics. With Telegraf, you have the option to filter and select which metrics you want to be sent to your output storage. Here is the full list of available metrics: