guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

08/11: Include tablespace as a label for table metrics


From: Christopher Baines
Subject: 08/11: Include tablespace as a label for table metrics
Date: Fri, 9 Oct 2020 15:21:20 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit 3cb8ce51fcc0b319f0e49d9a71cfef5bf46786fc
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Fri Oct 9 19:35:31 2020 +0100

    Include tablespace as a label for table metrics
    
    As this will make it easier to tell where space is going.
---
 guix-data-service/metrics.scm        |  9 +++++++--
 guix-data-service/web/controller.scm | 12 ++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/guix-data-service/metrics.scm b/guix-data-service/metrics.scm
index 19dc0d5..50be722 100644
--- a/guix-data-service/metrics.scm
+++ b/guix-data-service/metrics.scm
@@ -38,6 +38,7 @@ WITH RECURSIVE pg_inherit(inhrelid, inhparent) AS (
   WHERE inhparent NOT IN (SELECT inhrelid FROM pg_inherit)
 )
 SELECT table_name,
+       COALESCE(pg_tablespace.spcname,'default') AS tablespace,
        row_estimate,
        table_bytes,
        index_bytes,
@@ -48,6 +49,7 @@ FROM (
     SELECT c.oid,
            nspname AS table_schema,
            relname AS table_name,
+           reltablespace AS tablespace_id,
            SUM(c.reltuples) OVER (partition BY parent) AS row_estimate,
            SUM(pg_total_relation_size(c.oid)) OVER (partition BY parent) AS 
total_bytes,
            SUM(pg_indexes_size(c.oid)) OVER (partition BY parent) AS 
index_bytes,
@@ -58,6 +60,7 @@ FROM (
              reltuples,
              relname,
              relnamespace,
+             reltablespace,
              pg_class.reltoastrelid,
              COALESCE(inhparent, pg_class.oid) parent
       FROM pg_class
@@ -68,11 +71,13 @@ FROM (
   ) a
   WHERE oid = parent
     AND table_schema = 'guix_data_service'
-) a;")
+) a
+LEFT JOIN pg_tablespace ON tablespace_id = pg_tablespace.oid")
 
   (map (match-lambda
-         ((name row-estimate table-bytes index-bytes toast-bytes)
+         ((name tablespace row-estimate table-bytes index-bytes toast-bytes)
           (list name
+                tablespace
                 (or (string->number row-estimate) 0)
                 (or (string->number table-bytes) 0)
                 (or (string->number index-bytes) 0)
diff --git a/guix-data-service/web/controller.scm 
b/guix-data-service/web/controller.scm
index 7e162aa..a650889 100644
--- a/guix-data-service/web/controller.scm
+++ b/guix-data-service/web/controller.scm
@@ -146,20 +146,24 @@
                   select-load-new-guix-revision-job-metrics)))
 
         (for-each (match-lambda
-                    ((name row-estimate table-bytes index-bytes toast-bytes)
+                    ((name tablespace row-estimate
+                           table-bytes index-bytes toast-bytes)
 
                      (metric-set table-row-estimate-metric
                                  row-estimate
                                  #:label-values `((name . ,name)))
                      (metric-set table-bytes-metric
                                  table-bytes
-                                 #:label-values `((name . ,name)))
+                                 #:label-values `((name       . ,name)
+                                                  (tablespace . ,tablespace)))
                      (metric-set table-index-bytes-metric
                                  index-bytes
-                                 #:label-values `((name . ,name)))
+                                 #:label-values `((name       . ,name)
+                                                  (tablespace . ,tablespace)))
                      (metric-set table-toast-bytes-metric
                                  toast-bytes
-                                 #:label-values `((name . ,name)))))
+                                 #:label-values `((name       . ,name)
+                                                  (tablespace . 
,tablespace)))))
                   metric-values)
 
         (metric-set revisions-count-metric



reply via email to

[Prev in Thread] Current Thread [Next in Thread]