diff options
author | Christopher Baines <mail@cbaines.net> | 2023-02-04 11:13:24 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-02-04 11:13:24 +0100 |
commit | b2ad8e04693759656caa6560315b8325a2079ba1 (patch) | |
tree | 96440cf9b73f5f8105a91331f4727e645815c314 | |
parent | ccdd0f889c8e0d3c5961eb74b6eefb2c18b60807 (diff) | |
download | nar-herder-b2ad8e04693759656caa6560315b8325a2079ba1.tar nar-herder-b2ad8e04693759656caa6560315b8325a2079ba1.tar.gz |
Instrument the cached bytes by compression
-rw-r--r-- | nar-herder/cached-compression.scm | 33 | ||||
-rw-r--r-- | scripts/nar-herder.in | 1 |
2 files changed, 30 insertions, 4 deletions
diff --git a/nar-herder/cached-compression.scm b/nar-herder/cached-compression.scm index 0e91368..d82a9e2 100644 --- a/nar-herder/cached-compression.scm +++ b/nar-herder/cached-compression.scm @@ -25,6 +25,7 @@ #:use-module (ice-9 atomic) #:use-module (ice-9 threads) #:use-module (logging logger) + #:use-module (prometheus) #:use-module (web uri) #:use-module (web client) #:use-module (web response) @@ -177,11 +178,17 @@ (define* (make-maybe-trigger-creation-of-compressed-nars database + metrics-registry nar-source enabled-cached-compressions cached-compression-min-uses #:key (cached-compression-workers 2)) + (define nar-cache-bytes-metric + (make-gauge-metric metrics-registry + "nar_cache_size_bytes" + #:labels '(compression))) + (let ((consider-nar-request-channel (make-worker-thread-set (lambda () @@ -191,6 +198,16 @@ cached-bytes-by-compression-box (perform-cached-compression-startup database enabled-cached-compressions)) + + (for-each + (match-lambda + ((compression . bytes) + (metric-set + nar-cache-bytes-metric + bytes + #:label-values `((compression . ,compression))))) + (atomic-box-ref cached-bytes-by-compression-box)) + (list cached-bytes-by-compression-box))) ;; Just make one thread, as this thread won't do much work ;; and relies on a hash table that shouldn't be accessed by @@ -255,14 +272,22 @@ (monitor (let* ((cached-bytes-by-compression (atomic-box-ref - cached-bytes-by-compression-box))) + cached-bytes-by-compression-box)) + (updated-bytes-for-compression + (+ (assq-ref cached-bytes-by-compression + missing-compression) + new-bytes))) + + (metric-set + nar-cache-bytes-metric + updated-bytes-for-compression + #:label-values `((compression . ,missing-compression))) + (atomic-box-set! cached-bytes-by-compression-box (alist-cons missing-compression - (+ (assq-ref cached-bytes-by-compression - missing-compression) - new-bytes) + updated-bytes-for-compression (alist-delete missing-compression cached-bytes-by-compression))) diff --git a/scripts/nar-herder.in b/scripts/nar-herder.in index 0b38995..829b23a 100644 --- a/scripts/nar-herder.in +++ b/scripts/nar-herder.in @@ -485,6 +485,7 @@ #f (make-maybe-trigger-creation-of-compressed-nars database + metrics-registry (or (assq-ref opts 'cached-compression-nar-source) canonical-storage) enabled-cached-compressions |