[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Expose metrics from pg_stats
From: |
Christopher Baines |
Subject: |
branch master updated: Expose metrics from pg_stats |
Date: |
Tue, 29 Nov 2022 06:10:09 -0500 |
This is an automated email from the git hooks/post-receive script.
cbaines pushed a commit to branch master
in repository data-service.
The following commit(s) were added to refs/heads/master by this push:
new 7b69611 Expose metrics from pg_stats
7b69611 is described below
commit 7b69611755ac3b9132710d83a1139b4c5606578d
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Tue Nov 29 11:09:55 2022 +0000
Expose metrics from pg_stats
---
guix-data-service/metrics.scm | 20 ++++++++++++++++++-
guix-data-service/web/controller.scm | 37 ++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/guix-data-service/metrics.scm b/guix-data-service/metrics.scm
index 7af8924..7ec6b8e 100644
--- a/guix-data-service/metrics.scm
+++ b/guix-data-service/metrics.scm
@@ -20,7 +20,8 @@
#:use-module (squee)
#:export (fetch-high-level-table-size-metrics
fetch-pg-stat-user-tables-metrics
- fetch-pg-stat-user-indexes-metrics))
+ fetch-pg-stat-user-indexes-metrics
+ fetch-pg-stats-metrics))
(define (fetch-high-level-table-size-metrics conn)
;; Adapted from https://wiki.postgresql.org/wiki/Disk_Usage
@@ -155,3 +156,20 @@ WHERE pg_stat_user_indexes.schemaname =
'guix_data_service'")
(idx-tup-fetch . ,idx_tup_fetch)
(bytes . ,size_in_bytes))))
(exec-query conn query)))
+
+(define (fetch-pg-stats-metrics conn)
+ (define query
+ "
+SELECT tablename, attname, null_frac, n_distinct, correlation
+FROM pg_stats
+WHERE schemaname = 'guix_data_service'")
+
+ (map
+ (match-lambda
+ ((tablename attname null_frac n_distinct correlation)
+ `((table-name . ,tablename)
+ (column-name . ,attname)
+ (null-frac . ,(string->number null_frac))
+ (n-distinct . ,(string->number n_distinct))
+ (correlation . ,(and=> correlation string->number)))))
+ (exec-query conn query)))
diff --git a/guix-data-service/web/controller.scm
b/guix-data-service/web/controller.scm
index 7aac071..988145e 100644
--- a/guix-data-service/web/controller.scm
+++ b/guix-data-service/web/controller.scm
@@ -151,6 +151,22 @@
#:labels '(name))))
pg-stat-indexes-fields))
+ (pg-stats-fields '(null-frac n-distinct correlation))
+
+ (pg-stats-metrics (map (lambda (field)
+ (cons
+ field
+ (make-gauge-metric
+ registry
+ (string-append
+ "pg_stats_"
+ (string-replace-substring
+ (symbol->string field)
+ "-"
+ "_"))
+ #:labels '(table column))))
+ pg-stats-fields))
+
(gc-metrics-updater
(get-gc-metrics-updater registry)))
@@ -167,6 +183,9 @@
(pg-stat-user-indexes-metrics
(with-thread-postgresql-connection
fetch-pg-stat-user-indexes-metrics))
+ (pg-stats-metric-values
+ (with-thread-postgresql-connection
+ fetch-pg-stats-metrics))
(load-new-guix-revision-job-metrics
(with-thread-postgresql-connection
select-load-new-guix-revision-job-metrics)))
@@ -228,6 +247,24 @@
field-values)))
pg-stat-user-indexes-metrics)
+ (map (lambda (field-values)
+ (let ((table (assq-ref field-values 'table-name))
+ (column (assq-ref field-values 'column-name)))
+ (for-each
+ (match-lambda
+ (('table-name . _) #f)
+ (('column-name . _) #f)
+ ((_ . #f) #f)
+ ((field . value)
+ (let ((metric (or (assq-ref pg-stats-metrics field)
+ (error field))))
+ (metric-set metric
+ value
+ #:label-values `((table . ,table)
+ (column . ,column))))))
+ field-values)))
+ pg-stats-metric-values)
+
(for-each (match-lambda
((repository-label state count)
(metric-set
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Expose metrics from pg_stats,
Christopher Baines <=