guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/02: Add metrics for ports and file descriptors


From: Christopher Baines
Subject: 02/02: Add metrics for ports and file descriptors
Date: Sun, 10 Sep 2023 04:58:00 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit 893cccf8e5b51f6a05f12ade404303ab9d6db795
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Thu Sep 7 11:16:45 2023 +0100

    Add metrics for ports and file descriptors
---
 guix-data-service/utils.scm          | 25 +++++++++++++++++++++++++
 guix-data-service/web/controller.scm |  6 +++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/guix-data-service/utils.scm b/guix-data-service/utils.scm
index 361d7c8..9dd94df 100644
--- a/guix-data-service/utils.scm
+++ b/guix-data-service/utils.scm
@@ -18,6 +18,7 @@
 (define-module (guix-data-service utils)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-11)
+  #:use-module (ice-9 ftw)
   #:use-module (ice-9 match)
   #:use-module (ice-9 format)
   #:use-module (ice-9 threads)
@@ -48,6 +49,7 @@
             delete-duplicates/sort!
 
             get-gc-metrics-updater
+            get-port-metrics-updater
 
             call-with-sigint
             run-server/patched))
@@ -451,6 +453,29 @@ available.  Return the resource once PROC has returned."
             (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 '("." "..")))))
+            '()))))))
+
 ;; This variant of run-server from the fibers library supports running
 ;; multiple servers within one process.
 (define run-server/patched
diff --git a/guix-data-service/web/controller.scm 
b/guix-data-service/web/controller.scm
index a0b847c..a7ed02c 100644
--- a/guix-data-service/web/controller.scm
+++ b/guix-data-service/web/controller.scm
@@ -193,7 +193,10 @@
                          #:labels '(pool_name)))))
 
          (gc-metrics-updater
-          (get-gc-metrics-updater registry)))
+          (get-gc-metrics-updater registry))
+
+         (port-metrics-updater
+          (get-port-metrics-updater registry)))
 
     (define guile-time-metrics-updater
       (let ((internal-real-time
@@ -399,6 +402,7 @@
                   (or load-new-guix-revision-job-metrics '()))
 
         (gc-metrics-updater)
+        (port-metrics-updater)
         (guile-time-metrics-updater)
 
         (list (build-response



reply via email to

[Prev in Thread] Current Thread [Next in Thread]