diff options
author | Christopher Baines <mail@cbaines.net> | 2020-12-01 22:42:41 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-12-01 22:42:41 +0000 |
commit | 9c9e702553c5bf9edfac34b4ed6fa1c4a6ec6e38 (patch) | |
tree | 709cbdd34289647d9867bc328d6026ac1c25c9c6 | |
parent | 37e78be1336870ebff07b644f6fb228bf484b702 (diff) | |
download | build-coordinator-9c9e702553c5bf9edfac34b4ed6fa1c4a6ec6e38.tar build-coordinator-9c9e702553c5bf9edfac34b4ed6fa1c4a6ec6e38.tar.gz |
Add metrics for the database and WAL size
I particularly want to monitor the WAL growth, as I don't think SQLite's usual
approach to keeping the size down is sufficient.
-rw-r--r-- | guix-build-coordinator/agent-messaging/http/server.scm | 3 | ||||
-rw-r--r-- | guix-build-coordinator/datastore.scm | 1 | ||||
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 27 |
3 files changed, 31 insertions, 0 deletions
diff --git a/guix-build-coordinator/agent-messaging/http/server.scm b/guix-build-coordinator/agent-messaging/http/server.scm index 8546b70..098253c 100644 --- a/guix-build-coordinator/agent-messaging/http/server.scm +++ b/guix-build-coordinator/agent-messaging/http/server.scm @@ -181,6 +181,9 @@ port. Also, the port used can be changed by passing the --port option.\n" (metric-set internal-run-time (get-internal-run-time)) + ;; These are the db size metrics + (datastore-update-metrics! datastore) + (for-each (match-lambda ((system . count) (metric-set builds-total diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm index b4a37b3..c1ad5ad 100644 --- a/guix-build-coordinator/datastore.scm +++ b/guix-build-coordinator/datastore.scm @@ -8,6 +8,7 @@ #:export (database-uri->datastore datastore-find-build-output)) +(re-export datastore-update-metrics!) (re-export datastore-update) (re-export datastore-call-with-transaction) (re-export datastore-store-derivation) diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index 11dc06e..b802f84 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -12,6 +12,7 @@ #:use-module (guix-build-coordinator config) #:use-module (guix-build-coordinator datastore abstract) #:export (sqlite-datastore + datastore-update-metrics! datastore-update datastore-call-with-transaction datastore-store-derivation @@ -157,6 +158,32 @@ datastore)) +(define-method (datastore-update-metrics! + (datastore <sqlite-datastore>)) + (let* ((db-filename + (slot-ref datastore 'database-file)) + (db-wal-filename + (string-append db-filename "-wal")) + + (registry + (slot-ref datastore 'metrics-registry)) + (db-bytes + (or (metrics-registry-fetch-metric registry + "datastore_bytes") + (make-gauge-metric + registry "datastore_bytes" + #:docstring "Size of the SQLite database file"))) + (db-wal-bytes + (or (metrics-registry-fetch-metric registry + "datastore_wal_bytes") + (make-gauge-metric + registry "datastore_wal_bytes" + #:docstring "Size of the SQLite Write Ahead Log file")))) + + (metric-set db-bytes (stat:size (stat db-filename))) + (metric-set db-wal-bytes (stat:size (stat db-wal-filename)))) + #t) + (define (call-with-time-tracking datastore thing thunk) (define registry (slot-ref datastore 'metrics-registry)) (define metric-name |