From 399b9b08bf1191faea84c5262b94fcb91b544934 Mon Sep 17 00:00:00 2001 From: Thomas Hahn Date: Wed, 2 Aug 2023 16:40:18 -0700 Subject: [PATCH] Fix for Postgres max connections. Postgres does not limit connections by database, but total over the server. Additionally, alert labels didn't match across the pair. Using a min by on the right side deals with the possibility additional labels are present on your exporter. --- _data/rules.yml | 2 +- dist/rules/postgresql/postgres-exporter.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_data/rules.yml b/_data/rules.yml index 3f92066..6b7036b 100644 --- a/_data/rules.yml +++ b/_data/rules.yml @@ -619,7 +619,7 @@ groups: severity: warning - name: Postgresql too many connections description: PostgreSQL instance has too many connections (> 80%). - query: 'sum by (datname) (pg_stat_activity_count{datname!~"template.*|postgres"}) > pg_settings_max_connections * 0.8' + expr: 'sum by (instance, job, server) (pg_stat_activity_count) > min by (instance, job, server) (pg_settings_max_connections * 0.8)' severity: warning for: 2m - name: Postgresql not enough connections diff --git a/dist/rules/postgresql/postgres-exporter.yml b/dist/rules/postgresql/postgres-exporter.yml index b3999f8..e9dc0b5 100644 --- a/dist/rules/postgresql/postgres-exporter.yml +++ b/dist/rules/postgresql/postgres-exporter.yml @@ -50,7 +50,7 @@ groups: description: "Table {{ $labels.relname }} has not been auto analyzed for 10 days\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" - alert: PostgresqlTooManyConnections - expr: 'sum by (datname) (pg_stat_activity_count{datname!~"template.*|postgres"}) > pg_settings_max_connections * 0.8' + expr: 'sum by (instance, job, server) (pg_stat_activity_count) > min by (instance, job, server) (pg_settings_max_connections * 0.8)' for: 2m labels: severity: warning