Package: prometheus-pgbouncer-exporter
Prometheus exporter for PgBouncerHow to use itYou have two options to use it:Manually install and run theprometheus-pgbouncer-exporterPython packageUse theDocker image available on Docker hub(see instructions on Docker hub)How to manually install and run itThe following will install the exporter whose entrypoint binary is calledpgbouncer-exporter:pip3 install prometheus-pgbouncer-exporterThe exporter accepts configuration via config file, you can specify with--configargument:pgbouncer-exporter --config ./config.ymlAvailable arguments:--config CONFIG         Path to config file
--log-level LOG_LEVEL   Minimum log level. Accepted values are: DEBUG, INFO,
                        WARNING, ERROR, CRITICAL
--log-file LOG_FILE     Path to log file or 'stdout' to log on console. Signal
                        with -HUP to re-open log file descriptorFeaturesSupports multiple pgbouncer instancesAllow to configure extra labels for each pgbouncer instanceAllow to configure timeouts on pgbouncer connectionsAllow to filter databases for which metrics are exported withinclude_databasesandexclude_databasesWhy supporting multiple pgbouncer instances?PgBouncer is a single thread application and so can only saturate a single CPU core on high load. In high load environments, it's common practice to run multiple pgbouncer processes per machine (one for each CPU core) and load balance traffic among them. Ideally we want to run a single exporter instance per machine, capable to monitor 1+ pgbouncer(s) running on the machine itself.Exported metricsThe exporter exports the following metrics for each monitored pgbouncer instance:Metric nameTypePgBouncerDescriptionpgbouncer_stats_requests_totalcounter<= 1.7Total number of requests pooled. Could be transactions or queries, depending on pool mode. (labels:database)pgbouncer_stats_queries_totalcounter>= 1.8Total number of SQL queries pooled by pgbouncer (labels:database)pgbouncer_stats_queries_duration_microsecondscounterallTotal number of microseconds spent waiting for a server to return a query response. Includes time spent waiting for an available connection. (labels:database)pgbouncer_stats_waiting_duration_microsecondscounter>= 1.8Total number of microseconds spent waiting for an available connection. (labels:database)pgbouncer_stats_received_bytes_totalcounterallTotal volume in bytes of network traffic received by pgbouncer (labels:database)pgbouncer_stats_sent_bytes_totalcounterallTotal volume in bytes of network traffic sent by pgbouncer (labels:database)pgbouncer_stats_transactions_totalcounter>= 1.8Total number of SQL transactions pooled by pgbouncer (labels:database)pgbouncer_stats_transactions_duration_microsecondscounter>= 1.8Total number of microseconds spent in a transaction. Includes time spent waiting for an available connection. (labels:database)pgbouncer_pools_client_active_connectionsgaugeallClient connections that are linked to server connection and can process queries (labels:database,user)pgbouncer_pools_client_waiting_connectionsgaugeallClient connections have sent queries but have not yet got a server connection (labels:database,user)pgbouncer_pools_server_active_connectionsgaugeallServer connections that linked to client (labels:database,user)pgbouncer_pools_server_idle_connectionsgaugeallServer connections that unused and immediately usable for client queries (labels:database,user)pgbouncer_pools_server_used_connectionsgaugeallServer connections that have been idle more than server_check_delay, so they needs server_check_query to run on it before it can be used (labels:database,user)pgbouncer_pools_server_testing_connectionsgaugeallServer connections that are currently running either server_reset_query or server_check_query (labels:database,user)pgbouncer_pools_server_login_connectionsgaugeallServer connections currently in logging in process (labels:database,user)pgbouncer_pools_client_maxwait_secondsgaugeallHow long the first (oldest) client in queue has waited, in seconds (labels:database,user)pgbouncer_databases_database_pool_sizegaugeallConfigured pool size limit (labels:database,backend_database)pgbouncer_databases_database_reserve_pool_sizegaugeallConfigured reserve limit (labels:database,backend_database)pgbouncer_databases_database_current_connectionsgaugeallTotal number of per-database Database connections count (labels:database,backend_database)pgbouncer_databases_database_max_connectionsgaugeallMaximum number of allowed connections per-database (labels:database,backend_database)pgbouncer_config_max_client_conngaugeallConfiguration of maximum number of allowed client connectionspgbouncer_config_max_user_connectionsgaugeallConfiguration of maximum number of server connections per userConfiguration fileThe exporter read the configuration from a yaml config file with the following syntax:# The host on which the exporter should listen to (defaults to 127.0.0.1)exporter_host:0.0.0.0# The port on which the exporter should listen to (defaults to 9100)exporter_port:9100# The list of pgbouncer instances to monitorpgbouncers:-# The pgbouncer connection string. Supports environment variables replacement# Ie. $(PGBOUNCER_PASS) is replaced with the content of "PGBOUNCER_PASS" environment#     variable if exist, or left untouched if doesn't existdsn:postgresql://pgbouncer:$(PGBOUNCER_PASS)@localhost:6431/pgbouncer# The pgbouncer connection timeout in seconds (defaults to 5 seconds)connect_timeout:5# Databases to report metrics for. If omitted or empty, all databases# will be reported.include_databases:# Databases to exclude from metrics reporting. If omitted or empty, all# databases matching "include_databases" will be reported.exclude_databases:-pgbouncer# Extra labels to add to all metrics exported for this pgbouncer# instance. Required if you have configured multiple pgbouncers,# in order to export an unique set of metrics.extra_labels:pool_id:1-dsn:postgresql://pgbouncer:$(PGBOUNCER_PASS)@localhost:6432/pgbouncerexclude_databases:-pgbouncerextra_labels:pool_id:2Environment variables replacementThe configuration file supports environment variables replacement. If you use the syntax$(NAME)in any setting value, it gets replaced by the content ofNAMEenvironment variable or left untouched if theNAMEenvironment variable does not exist.How to contributeRun thedevelopment environment:docker-compose build && docker-compose run devThen inside the container:# Run tests
python -m unittest

# Run exporter
python -m prometheus_pgbouncer_exporter.cli --config ./config.yml

# Run linter
pycodestyle --max-line-length=300 prometheus_pgbouncer_exporter/*.pyHow to publish a new versionRelease python package:Update version insetup.pyUpdateCHANGELOG.mdRelease new version on GitHubRunpython3 setup.py sdistUpload it withtwine upload dist/*Upload the files to the Github releaseRelease Docker image:Update package version inDockerfileBuild imagedocker rmi -f prometheus-pgbouncer-exporter && \
docker build -t prometheus-pgbouncer-exporter .Tag the image and push it to Docker Hubdocker tag prometheus-pgbouncer-exporter spreaker/prometheus-pgbouncer-exporter:latest && \
docker push spreaker/prometheus-pgbouncer-exporter:latest

docker tag prometheus-pgbouncer-exporter spreaker/prometheus-pgbouncer-exporter:2.0.3 && \
docker push spreaker/prometheus-pgbouncer-exporter:2.0.3LicenseThis software is released under theMIT license.