Report the size of the guix database and WAL file

Since the Guix daemon doesn't export these metrics, instrument it here.
This commit is contained in:
Christopher Baines 2024-03-05 11:15:04 +00:00
parent ca69d3329d
commit 184d341671
2 changed files with 26 additions and 1 deletions

View file

@ -57,6 +57,7 @@
get-gc-metrics-updater
get-port-metrics-updater
get-guix-metrics-updater
call-with-sigint
run-server/patched
@ -628,6 +629,26 @@ available. Return the resource once PROC has returned."
(not (member file '("." "..")))))
'()))))))
(define (get-guix-metrics-updater registry)
(define guix-db "/var/guix/db/db.sqlite")
(define guix-db-wal (string-append guix-db "-wal"))
(let ((guix-db-bytes-metric
(make-gauge-metric registry "guix_db_bytes"))
(guix-db-wal-bytes-metric
(make-gauge-metric registry "guix_db_wal_bytes")))
(lambda ()
(with-exception-handler
(lambda _
#f)
(lambda ()
(metric-set guix-db-bytes-metric (stat:size (stat guix-db)))
(metric-set guix-db-wal-bytes-metric
(if (file-exists? guix-db-wal)
(stat:size (stat guix-db-wal))
0)))
#:unwind? #t))))
;; This variant of run-server from the fibers library supports running
;; multiple servers within one process.
(define run-server/patched

View file

@ -201,7 +201,10 @@
(get-gc-metrics-updater registry))
(port-metrics-updater
(get-port-metrics-updater registry)))
(get-port-metrics-updater registry))
(guix-metrics-updater
(get-guix-metrics-updater registry)))
(define guile-time-metrics-updater
(let ((internal-real-time
@ -437,6 +440,7 @@
(gc-metrics-updater)
(port-metrics-updater)
(guix-metrics-updater)
(guile-time-metrics-updater)
(list (build-response