From d75181ebeba1caa8663e09b9dbe504912b199edf Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 17 Apr 2024 09:35:58 +0100 Subject: Use the new process metrics exporter --- .../agent-messaging/http/server.scm | 21 +++++---- guix-build-coordinator/utils.scm | 51 ---------------------- 2 files changed, 13 insertions(+), 59 deletions(-) diff --git a/guix-build-coordinator/agent-messaging/http/server.scm b/guix-build-coordinator/agent-messaging/http/server.scm index 7bfc0b5..85ba0d4 100644 --- a/guix-build-coordinator/agent-messaging/http/server.scm +++ b/guix-build-coordinator/agent-messaging/http/server.scm @@ -137,13 +137,14 @@ INTERVAL (a time-duration object), otherwise does nothing and returns #f." build-coordinator chunked-request-channel output-hash-channel) + (define plain-metrics-registry + (make-metrics-registry)) + (define gc-metrics-updater - (get-gc-metrics-updater - (build-coordinator-metrics-registry build-coordinator))) + (get-gc-metrics-updater plain-metrics-registry)) - (define port-metrics-updater - (get-port-metrics-updater - (build-coordinator-metrics-registry build-coordinator))) + (define process-metrics-updater + (get-process-metrics-updater plain-metrics-registry)) (define thread-metric (make-gauge-metric @@ -157,7 +158,7 @@ INTERVAL (a time-duration object), otherwise does nothing and returns #f." (call-with-delay-logging gc-metrics-updater) (metric-set thread-metric (length (all-threads))) - (call-with-delay-logging port-metrics-updater) + (call-with-delay-logging process-metrics-updater) (call-with-delay-logging datastore-metrics-updater)) (with-exception-handler @@ -184,7 +185,8 @@ INTERVAL (a time-duration object), otherwise does nothing and returns #f." build-coordinator chunked-request-channel output-hash-channel - update-managed-metrics!))) + update-managed-metrics! + plain-metrics-registry))) #:host host #:port port)) #:unwind? #t)) @@ -614,7 +616,8 @@ INTERVAL (a time-duration object), otherwise does nothing and returns #f." build-coordinator chunked-request-channel output-hash-channel - update-managed-metrics!) + update-managed-metrics! + plain-metrics-registry) (define (authenticated? uuid request) (let* ((authorization-base64 (match (assq-ref (request-headers request) @@ -1015,6 +1018,8 @@ INTERVAL (a time-duration object), otherwise does nothing and returns #f." (lambda (port) (write-metrics (build-coordinator-metrics-registry build-coordinator) + port) + (write-metrics plain-metrics-registry port)))))) (_ (render-json diff --git a/guix-build-coordinator/utils.scm b/guix-build-coordinator/utils.scm index 053730b..a549f20 100644 --- a/guix-build-coordinator/utils.scm +++ b/guix-build-coordinator/utils.scm @@ -96,8 +96,6 @@ running-on-the-hurd? - get-gc-metrics-updater - get-port-metrics-updater get-guix-memory-metrics-updater open-socket-for-uri* @@ -1329,55 +1327,6 @@ again." (set! cached-system (utsname:sysname (uname)))) (string=? cached-system "GNU"))) -(define (get-gc-metrics-updater registry) - (define metrics - `((gc-time-taken - . ,(make-gauge-metric registry "guile_gc_time_taken")) - (heap-size - . ,(make-gauge-metric registry "guile_heap_size")) - (heap-free-size - . ,(make-gauge-metric registry "guile_heap_free_size")) - (heap-total-allocated - . ,(make-gauge-metric registry "guile_heap_total_allocated")) - (heap-allocated-since-gc - . ,(make-gauge-metric registry "guile_allocated_since_gc")) - (protected-objects - . ,(make-gauge-metric registry "guile_gc_protected_objects")) - (gc-times - . ,(make-gauge-metric registry "guile_gc_times")))) - - (lambda () - (let ((stats (gc-stats))) - (for-each - (match-lambda - ((name . metric) - (let ((value (assq-ref stats name))) - (metric-set metric value)))) - metrics)))) - -(define (get-port-metrics-updater registry) - (let ((ports-metric - (make-gauge-metric registry "guile_ports_total")) - (fds-metric - (make-gauge-metric registry "file_descriptors_total"))) - (lambda () - (let ((count 0)) - (port-for-each - (lambda _ - (set! count (+ 1 count)))) - - (metric-set ports-metric count)) - - (metric-set - fds-metric - (length - ;; In theory 'scandir' cannot return #f, but in practice, - ;; we've seen it before. - (or (scandir "/proc/self/fd" - (lambda (file) - (not (member file '("." ".."))))) - '())))))) - (define (get-guix-memory-metrics-updater registry) (define %memoization-tables (@@ (guix memoization) %memoization-tables)) -- cgit v1.2.3