summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-11-28 10:58:02 +0000
committerChristopher Baines <mail@cbaines.net>2020-12-07 09:08:20 +0000
commitfd14385581e4f3f8285442a0e1cc17d320d35fa9 (patch)
treeffb45b7c994a057299b89847fe57494d7138239d
parent6eba27f7beb1320b1abd6123d969663e5a460f77 (diff)
downloadguix-fd14385581e4f3f8285442a0e1cc17d320d35fa9.tar.gz
prometheus-node-exporter: Enable the textfile collector.
* gnu/services/monitoring.scm (<prometheus-node-exporter-configuration>): Add
textfile-directory.
(prometheus-node-exporter-textfile-directory,
prometheus-node-exporter-activation): New procedures.
(prometheus-node-exporter-shepherd-service): Pass
--collector.textfile.directoryto the service.
(prometheus-node-exporter-service-type): Extend the activation service type.
* doc/guix.texi (Prometheus Node Exporter Service): Document.
-rw-r--r--doc/guix.texi5
-rw-r--r--gnu/services/monitoring.scm27
2 files changed, 29 insertions, 3 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index b5340aa368..13e0dcf6b7 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -22038,6 +22038,11 @@ The prometheus-node-exporter package to use.
 @item @code{web-listen-address} (default: @code{":9100"})
 Bind the web interface to the specified address.
 
+@item @code{textfile-directory} (default: @code{"/var/lib/prometheus/node-exporter"})
+This directory can be used to export metrics specific to this machine.
+Files containing metrics in the text format, with the filename ending in
+@code{.prom} should be placed in this directory.
+
 @end table
 @end deftp
 
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index faa1e71dcb..a7fd4328cf 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -126,7 +126,9 @@ HTTP.")
   (package prometheus-node-exporter-configuration-package
            (default go-github-com-prometheus-node-exporter))
   (web-listen-address prometheus-node-exporter-web-listen-address
-                      (default ":9100")))
+                      (default ":9100"))
+  (textfile-directory prometheus-node-exporter-textfile-directory
+                      (default "/var/lib/prometheus/node-exporter")))
 
 (define %prometheus-node-exporter-accounts
   (list (user-account
@@ -143,7 +145,7 @@ HTTP.")
 (define prometheus-node-exporter-shepherd-service
   (match-lambda
     (( $ <prometheus-node-exporter-configuration>
-         package web-listen-address)
+         package web-listen-address textfile-directory)
      (list
       (shepherd-service
        (documentation "Prometheus node exporter.")
@@ -151,12 +153,29 @@ HTTP.")
        (requirement '(networking))
        (start #~(make-forkexec-constructor
                  (list #$(file-append package "/bin/node_exporter")
-                       "--web.listen-address" #$web-listen-address)
+                       "--web.listen-address" #$web-listen-address
+                       #$@(if textfile-directory
+                              (list "--collector.textfile.directory"
+                                    textfile-directory)
+                              '()))
                  #:user "prometheus-node-exporter"
                  #:group "prometheus-node-exporter"
                  #:log-file "/var/log/prometheus-node-exporter.log"))
        (stop #~(make-kill-destructor)))))))
 
+(define (prometheus-node-exporter-activation config)
+  (with-imported-modules '((guix build utils))
+    #~(let ((textfile-directory
+             #$(prometheus-node-exporter-textfile-directory config)))
+        (use-modules (guix build utils))
+
+        (when textfile-directory
+          (let ((user (getpw "prometheus-node-exporter")))
+            #t
+            (mkdir-p textfile-directory)
+            (chown textfile-directory (passwd:uid user) (passwd:gid user))
+            (chmod textfile-directory #o775))))))
+
 (define prometheus-node-exporter-service-type
   (service-type
    (name 'prometheus-node-exporter)
@@ -167,6 +186,8 @@ Prometheus.")
     (list
      (service-extension account-service-type
                         (const %prometheus-node-exporter-accounts))
+     (service-extension activation-service-type
+                        prometheus-node-exporter-activation)
      (service-extension shepherd-root-service-type
                         prometheus-node-exporter-shepherd-service)))
    (default-value (prometheus-node-exporter-configuration))))