aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-06-30 11:42:35 +0100
committerChristopher Baines <mail@cbaines.net>2024-07-02 14:39:33 +0200
commit09daad84faea3577acf5f1627e4bfed699b10a5d (patch)
tree86b77040cd8b9c7241db2f25174b35539ea9d21d /guix-build-coordinator
parentca0b2801be72e323a8782919ffb89166c558c3ba (diff)
downloadbuild-coordinator-09daad84faea3577acf5f1627e4bfed699b10a5d.tar
build-coordinator-09daad84faea3577acf5f1627e4bfed699b10a5d.tar.gz
Add dbstat metrics
Diffstat (limited to 'guix-build-coordinator')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm53
1 files changed, 53 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index c3b62b2..215c07e 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -351,6 +351,59 @@ PRAGMA optimize;")
(spawn-fiber
(lambda ()
+ (let* ((registry
+ (slot-ref datastore 'metrics-registry))
+ (dbstat-metrics
+ (map
+ (lambda (name)
+ (let ((metric-name
+ (string-append "datastore_dbstat_"
+ (symbol->string name))))
+ (cons
+ name
+ (or (metrics-registry-fetch-metric registry
+ metric-name)
+ (make-gauge-metric registry metric-name
+ #:labels '(name))))))
+ '(pageno ncell payload unused mx_payload pgsize))))
+
+ (while #t
+ (with-exception-handler
+ (lambda (exn)
+ (simple-format
+ (current-error-port)
+ "exception fetching dbstat metrics: ~A\n" exn))
+ (lambda ()
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT * FROM dbstat WHERE aggregate = true"
+ #:cache? #t))
+ (dbstat-columns
+ '(#f #f pageno #f ncell payload unused mx_payload #f pgsize)))
+ (sqlite-fold
+ (lambda (row _)
+ (for-each
+ (lambda (column val)
+ (when column
+ (metric-set (assq-ref dbstat-metrics column)
+ val
+ #:label-values
+ `((name . ,(vector-ref row 0))))))
+ dbstat-columns
+ (vector->list row)))
+ #f
+ statement)
+ (sqlite-reset statement))))
+ (sleep (* 60 60 60)))
+ #:unwind? #t)))))
+
+ (spawn-fiber
+ (lambda ()
(while #t
(sleep (* 60 10)) ; 10 minutes
(with-exception-handler