diff options
author | Christopher Baines <mail@cbaines.net> | 2024-06-30 11:42:35 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2024-07-02 14:39:33 +0200 |
commit | 09daad84faea3577acf5f1627e4bfed699b10a5d (patch) | |
tree | 86b77040cd8b9c7241db2f25174b35539ea9d21d /guix-build-coordinator/datastore/sqlite.scm | |
parent | ca0b2801be72e323a8782919ffb89166c558c3ba (diff) | |
download | build-coordinator-09daad84faea3577acf5f1627e4bfed699b10a5d.tar build-coordinator-09daad84faea3577acf5f1627e4bfed699b10a5d.tar.gz |
Add dbstat metrics
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 53 |
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 |