From 620f6a15bf490419160d544537607915749669f0 Mon Sep 17 00:00:00 2001 From: Roman Zaynetdinov Date: Thu, 7 Mar 2024 19:38:55 +0200 Subject: [PATCH 1/3] Export db size, deadlocks and changed row metrics We want to report metrics for the oldest user database. --- vm-image-spec.yaml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/vm-image-spec.yaml b/vm-image-spec.yaml index c1b7ad533a78..b0415ca4c6a0 100644 --- a/vm-image-spec.yaml +++ b/vm-image-spec.yaml @@ -142,6 +142,32 @@ files: query: | select datname, state, count(*) as count from pg_stat_activity where state <> '' group by datname, state; + - metric_name: pg_stats_userdb + type: gauge + help: 'Stats for the oldest non-system db' + key_labels: + - datname + value_label: kind + values: + - db_size + - deadlocks + # Rows + - inserted + - updated + - deleted + query: | + select pg_database_size(datname) as db_size, deadlocks, + tup_inserted as inserted, tup_updated as updated, tup_deleted as deleted, + datname + from pg_stat_database + where datname IN ( + select datname + from pg_database + where datname <> 'postgres' and not datistemplate + order by oid + limit 1 + ); + build: | # Build cgroup-tools # From 6d615af6793e5e556c3649644a798ef2b923985f Mon Sep 17 00:00:00 2001 From: Roman Zaynetdinov Date: Fri, 8 Mar 2024 14:19:26 +0200 Subject: [PATCH 2/3] Add db limit comment --- vm-image-spec.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vm-image-spec.yaml b/vm-image-spec.yaml index b0415ca4c6a0..043c50cfa6e0 100644 --- a/vm-image-spec.yaml +++ b/vm-image-spec.yaml @@ -155,6 +155,9 @@ files: - inserted - updated - deleted + # We export stats for only one non-system database. Without this limit + # it is too easy to abuse the system by creating lots of databases. + # We can try lifting this limit in the future after we understand the needs better. query: | select pg_database_size(datname) as db_size, deadlocks, tup_inserted as inserted, tup_updated as updated, tup_deleted as deleted, From 99891ad0a4d36a319b253dbca6ae11840b81f0ef Mon Sep 17 00:00:00 2001 From: Roman Zaynetdinov Date: Fri, 8 Mar 2024 15:09:01 +0200 Subject: [PATCH 3/3] Add max_cluster_size and db_total_size --- vm-image-spec.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vm-image-spec.yaml b/vm-image-spec.yaml index 043c50cfa6e0..5b93088303f5 100644 --- a/vm-image-spec.yaml +++ b/vm-image-spec.yaml @@ -171,6 +171,22 @@ files: limit 1 ); + - metric_name: max_cluster_size + type: gauge + help: 'neon.max_cluster_size setting' + key_labels: + values: [max_cluster_size] + query: | + select setting::int as max_cluster_size from pg_settings where name = 'neon.max_cluster_size'; + + - metric_name: db_total_size + type: gauge + help: 'Size of all databases' + key_labels: + values: [total] + query: | + select sum(pg_database_size(datname)) as total from pg_database; + build: | # Build cgroup-tools #