From 94b9f3cfbb23450c3089f81a6f1eef6d34fdb7ca Mon Sep 17 00:00:00 2001 From: Ted Hahn Date: Tue, 15 Aug 2023 10:39:41 -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. (#376) --- _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 57b202a..9948647 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