guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 01/08: monitoring: Log registered service names.


From: Ludovic Courtès
Subject: [shepherd] 01/08: monitoring: Log registered service names.
Date: Thu, 13 Apr 2023 05:43:11 -0400 (EDT)

civodul pushed a commit to branch wip-goopsless
in repository shepherd.

commit d884dca9a00a3ab8bcb0a5f7c98ea378abb3fdbd
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Apr 11 21:27:03 2023 +0200

    monitoring: Log registered service names.
    
    * modules/shepherd/service.scm (service-registry): Handle
    'service-name-count' messages.
    (service-name-count): New procedure.
    * modules/shepherd/service/monitoring.scm (log-monitoring-stats): Use
    it.
    * tests/services/monitoring.sh: Add test.
    * doc/shepherd.texi (Monitoring Service): Adjust example.
---
 doc/shepherd.texi                       |  2 +-
 modules/shepherd/service.scm            | 11 +++++++++++
 modules/shepherd/service/monitoring.scm |  3 ++-
 tests/services/monitoring.sh            |  1 +
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index e7a1dbd..62c123e 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -1451,7 +1451,7 @@ logging:
 
 @example
 $ herd log monitoring
-heap: 8.77 MiB; file descriptors: 20
+service names: 3; heap: 8.77 MiB; file descriptors: 20
 @end example
 
 You can also change the logging period; for instance, here is how you'd
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 8ff89db..a02398c 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -67,6 +67,7 @@
             lookup-service-action
             service-defines-action?
             with-service-registry
+            service-name-count
 
             action?
 
@@ -1034,6 +1035,9 @@ requests arriving on @var{channel}."
        (loop registered))
       (('service-list reply)
        (put-message reply (vlist->list registered))
+       (loop registered))
+      (('service-name-count reply)
+       (put-message reply (vlist-length registered))
        (loop registered)))))
 
 (define (essential-task-launcher name proc)
@@ -2143,6 +2147,13 @@ result.  Works in a manner akin to `fold' from SRFI-1."
 returned in unspecified."
   (fold-services cons '()))
 
+(define (service-name-count)
+  "Return the number of currently-registered service names."
+  (let ((reply (make-channel)))
+    (put-message (current-registry-channel)
+                 `(service-name-count ,reply))
+    (get-message* reply 5 'no-reply)))
+
 (define find-service
   (let ((reply (make-channel)))
     (lambda (pred)
diff --git a/modules/shepherd/service/monitoring.scm 
b/modules/shepherd/service/monitoring.scm
index 853eb58..cf812c9 100644
--- a/modules/shepherd/service/monitoring.scm
+++ b/modules/shepherd/service/monitoring.scm
@@ -28,7 +28,8 @@
 
 (define (log-monitoring-stats)
   "Log info about useful metrics: heap size, open file descriptors, etc."
-  (local-output (l10n "heap: ~,2f MiB; file descriptors: ~a")
+  (local-output (l10n "service names: ~a; heap: ~,2f MiB; file descriptors: 
~a")
+                (service-name-count)
                 (/ (assoc-ref (gc-stats) 'heap-size) (expt 2. 20))
                 (length
                  (or (scandir "/proc/self/fd"
diff --git a/tests/services/monitoring.sh b/tests/services/monitoring.sh
index 396f9f2..716eab9 100644
--- a/tests/services/monitoring.sh
+++ b/tests/services/monitoring.sh
@@ -55,6 +55,7 @@ test $n -lt 10
 
 $herd log monitoring
 $herd log monitoring | grep "heap:"
+$herd log monitoring | grep "service names: 3"
 $herd period monitoring 1
 ! $herd period monitoring not-a-number
 



reply via email to

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