From 327ca0ef0b28a95bc26c0551fdb980f6d9ad10db Mon Sep 17 00:00:00 2001 From: Phil Frost Date: Tue, 16 Oct 2018 12:04:08 -0400 Subject: [PATCH] Support new metrics in pgbouncer 1.8 Fixes https://github.com/spreaker/prometheus-pgbouncer-exporter/issues/5 --- README.md | 8 ++++++-- prometheus_pgbouncer_exporter/collector.py | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index feb0251..87e417c 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,14 @@ The exporter exports the following metrics for each monitored pgbouncer instance | Metric name | Type | Description | | -------------------------------------------------- | -------- | ---------------- | -| `pgbouncer_stats_queries_total` | counter | Total number of SQL queries pooled by pgbouncer (labels: `database`) | -| `pgbouncer_stats_queries_duration_microseconds` | counter | Total number of microseconds spent by pgbouncer when actively connected to PostgreSQL (labels: `database`) | +| `pgbouncer_stats_requests_total` | counter | Total number of requests pooled. Could be transactions or queries, depending on pool mode. (labels: `database`, pgbouncer < 1.8) | +| `pgbouncer_stats_queries_total` | counter | Total number of SQL queries pooled by pgbouncer (labels: `database`, pgbouncer >= 1.8) | +| `pgbouncer_stats_queries_duration_microseconds` | counter | Total number of microseconds spent waiting for a server to return a query response. Includes time spent waiting for an available connection. (labels: `database`, pgbouncer >= 1.8) | +| `pgbouncer_stats_waiting_duration_microseconds` | counter | Total number of microseconds spent waiting for an available connection. (labels: `database`, pgbouncer >= 1.8) | | `pgbouncer_stats_received_bytes_total` | counter | Total volume in bytes of network traffic received by pgbouncer (labels: `database`) | | `pgbouncer_stats_sent_bytes_total` | counter | Total volume in bytes of network traffic sent by pgbouncer (labels: `database`) | +| `pgbouncer_stats_transactions_total` | counter | Total number of SQL transactions pooled by pgbouncer (labels: `database`, pgbouncer >= 1.8) | +| `pgbouncer_stats_transactions_duration_microseconds`| counter | Total number of microseconds spent in a transaction. Includes time spent waiting for an available connection. (labels: `database`, pgbouncer >= 1.8) | | `pgbouncer_pools_client_active_connections` | gauge | Client connections that are linked to server connection and can process queries (labels: `database`, `user`) | | `pgbouncer_pools_client_waiting_connections` | gauge | Client connections have sent queries but have not yet got a server connection (labels: `database`, `user`) | | `pgbouncer_pools_server_active_connections` | gauge | Server connections that linked to client (labels: `database`, `user`) | diff --git a/prometheus_pgbouncer_exporter/collector.py b/prometheus_pgbouncer_exporter/collector.py index 2fdcaf1..591a61b 100644 --- a/prometheus_pgbouncer_exporter/collector.py +++ b/prometheus_pgbouncer_exporter/collector.py @@ -54,10 +54,20 @@ def collect(self): results = self._filterMetricsByIncludeDatabases(results, self.config.getIncludeDatabases()) results = self._filterMetricsByExcludeDatabases(results, self.config.getExcludeDatabases()) metrics += self._exportMetrics(results, "pgbouncer_stats_", [ - {"type": "counter", "column": "total_requests", "metric": "queries_total", "help": "Total number of SQL queries pooled by pgbouncer"}, - {"type": "counter", "column": "total_query_time", "metric": "queries_duration_microseconds", "help": "Total number of microseconds spent by pgbouncer when actively connected to PostgreSQL"}, - {"type": "counter", "column": "total_received", "metric": "received_bytes_total", "help": "Total volume in bytes of network traffic received by pgbouncer"}, - {"type": "counter", "column": "total_sent", "metric": "sent_bytes_total", "help": "Total volume in bytes of network traffic sent by pgbouncer"}, + # pgbouncer < 1.8 + {"type": "counter", "column": "total_requests", "metric": "requests_total", "help": "Total number of requests pooled. Could be transactions or queries, depending on pool mode."}, + + # pgbouncer >= 1.8 + {"type": "counter", "column": "total_xact_count", "metric": "transactions_total", "help": "Total number of transactions pooled"}, + {"type": "counter", "column": "total_query_count", "metric": "queries_total", "help": "Total number of queries pooled"}, + {"type": "counter", "column": "total_xact_time", "metric": "transactions_duration_microseconds", "help": "Total number of microseconds spent in a transaction. Includes time spent waiting for an available connection."}, + {"type": "counter", "column": "total_query_time", "metric": "queries_duration_microseconds", "help": "Total number of microseconds spent waiting for a server to return a query response. Includes time spent waiting for an available connection."}, + {"type": "counter", "column": "total_wait_time", "metric": "waiting_duration_microseconds", "help": "Total number of microseconds spent waiting for an available connection."}, + + # all versions + {"type": "counter", "column": "total_received", "metric": "received_bytes_total", "help": "Total volume in bytes of network traffic received by pgbouncer"}, + {"type": "counter", "column": "total_sent", "metric": "sent_bytes_total", "help": "Total volume in bytes of network traffic sent by pgbouncer"}, + ], {"database": "database"}, self.config.getExtraLabels()) else: success = False