all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements
@ 2020-11-28 12:04 Christopher Baines
  2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
  2020-12-06 22:27 ` [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements Ludovic Courtès
  0 siblings, 2 replies; 9+ messages in thread
From: Christopher Baines @ 2020-11-28 12:04 UTC (permalink / raw)
  To: 44922

[-- Attachment #1: Type: text/plain, Size: 664 bytes --]

Some patches to enhance the Prometheus node exporter service.

Christopher Baines (6):
  services: monitoring: Neaten up the Prometheus node exporter.
  monitoring: Add user and group for the Prometheus node exporter.
  services: monitoring: Use a log file for Prometheus node exporter.
  doc: Remove redundant node exporter configuration from the example.
  monitoring: Enable the Prometheus node exporter textfile collector.
  monitoring: Support extra options for the Prometheus node exporter.

 doc/guix.texi               | 15 ++++---
 gnu/services/monitoring.scm | 81 ++++++++++++++++++++++++++++++-------
 2 files changed, 76 insertions(+), 20 deletions(-)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter.
  2020-11-28 12:04 [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements Christopher Baines
@ 2020-11-28 12:11 ` Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 2/6] monitoring: Add user and group for " Christopher Baines
                     ` (4 more replies)
  2020-12-06 22:27 ` [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements Ludovic Courtès
  1 sibling, 5 replies; 9+ messages in thread
From: Christopher Baines @ 2020-11-28 12:11 UTC (permalink / raw)
  To: 44922

Add relevant exports, as well as a comment to better indicate where the
relevant code starts.

* gnu/services/monitoring.scm (prometheus-node-exporter-service-type):
Capitalise Prometheus.
---
 gnu/services/monitoring.scm | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index da3d736ba6..92df52b5ae 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -36,8 +36,12 @@
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-35)
   #:export (darkstat-configuration
-            prometheus-node-exporter-configuration
             darkstat-service-type
+
+            prometheus-node-exporter-configuration
+            prometheus-node-exporter-configuration?
+            prometheus-node-exporter-configuration-package
+            prometheus-node-exporter-web-listen-address
             prometheus-node-exporter-service-type
 
             zabbix-server-configuration
@@ -110,6 +114,11 @@ HTTP.")
           (service-extension shepherd-root-service-type
                              (compose list darkstat-shepherd-service))))))
 
+\f
+;;;
+;;; Prometheus node exporter
+;;;
+
 (define-record-type* <prometheus-node-exporter-configuration>
   prometheus-node-exporter-configuration
   make-prometheus-node-exporter-configuration
@@ -137,7 +146,7 @@ HTTP.")
    (name 'prometheus-node-exporter)
    (description
     "Run @command{node_exporter} to serve hardware and OS metrics to
-prometheus.")
+Prometheus.")
    (extensions
     (list (service-extension
            shepherd-root-service-type
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [bug#44922] [PATCH 2/6] monitoring: Add user and group for the Prometheus node exporter.
  2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
@ 2020-11-28 12:11   ` Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 3/6] services: monitoring: Use a log file for " Christopher Baines
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Christopher Baines @ 2020-11-28 12:11 UTC (permalink / raw)
  To: 44922

So it doesn't run as root, and because this will help with the textfile
exporter.

* gnu/services/monitoring.scm (%prometheus-node-exporter-accounts): New
variable.
(prometheus-node-exporter-shepherd-service): Use the relevant user and group.
(prometheus-node-exporter-service-type): Extend the account service type.
---
 gnu/services/monitoring.scm | 39 ++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index 92df52b5ae..d0934e7f27 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -128,18 +128,33 @@ HTTP.")
   (web-listen-address prometheus-node-exporter-web-listen-address
                       (default ":9100")))
 
+(define %prometheus-node-exporter-accounts
+  (list (user-account
+         (name "prometheus-node-exporter")
+         (group "prometheus-node-exporter")
+         (system? #t)
+         (comment "Prometheus node exporter daemon user")
+         (home-directory "/var/empty")
+         (shell (file-append shadow "/sbin/nologin")))
+        (user-group
+         (name "prometheus-node-exporter")
+         (system? #t))))
+
 (define prometheus-node-exporter-shepherd-service
   (match-lambda
     (( $ <prometheus-node-exporter-configuration>
          package web-listen-address)
-     (shepherd-service
-      (documentation "Prometheus node exporter.")
-      (provision '(prometheus-node-exporter))
-      (requirement '(networking))
-      (start #~(make-forkexec-constructor
-                (list #$(file-append package "/bin/node_exporter")
-                      "--web.listen-address" #$web-listen-address)))
-      (stop #~(make-kill-destructor))))))
+     (list
+      (shepherd-service
+       (documentation "Prometheus node exporter.")
+       (provision '(prometheus-node-exporter))
+       (requirement '(networking))
+       (start #~(make-forkexec-constructor
+                 (list #$(file-append package "/bin/node_exporter")
+                       "--web.listen-address" #$web-listen-address)
+                 #:user "prometheus-node-exporter"
+                 #:group "prometheus-node-exporter"))
+       (stop #~(make-kill-destructor)))))))
 
 (define prometheus-node-exporter-service-type
   (service-type
@@ -148,9 +163,11 @@ HTTP.")
     "Run @command{node_exporter} to serve hardware and OS metrics to
 Prometheus.")
    (extensions
-    (list (service-extension
-           shepherd-root-service-type
-           (compose list prometheus-node-exporter-shepherd-service))))
+    (list
+     (service-extension account-service-type
+                        (const %prometheus-node-exporter-accounts))
+     (service-extension shepherd-root-service-type
+                        prometheus-node-exporter-shepherd-service)))
    (default-value (prometheus-node-exporter-configuration))))
 
 \f
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [bug#44922] [PATCH 3/6] services: monitoring: Use a log file for Prometheus node exporter.
  2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 2/6] monitoring: Add user and group for " Christopher Baines
@ 2020-11-28 12:11   ` Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 4/6] doc: Remove redundant node exporter configuration from the example Christopher Baines
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Christopher Baines @ 2020-11-28 12:11 UTC (permalink / raw)
  To: 44922

This makes the logs easier to find and read.

* gnu/services/monitoring.scm (prometheus-node-exporter-shepherd-service):
Pass #:log-file to make-forkexec-constructor.
---
 gnu/services/monitoring.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index d0934e7f27..239306fa39 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -153,7 +153,8 @@ HTTP.")
                  (list #$(file-append package "/bin/node_exporter")
                        "--web.listen-address" #$web-listen-address)
                  #:user "prometheus-node-exporter"
-                 #:group "prometheus-node-exporter"))
+                 #:group "prometheus-node-exporter"
+                 #:log-file "/var/log/prometheus-node-exporter.log"))
        (stop #~(make-kill-destructor)))))))
 
 (define prometheus-node-exporter-service-type
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [bug#44922] [PATCH 4/6] doc: Remove redundant node exporter configuration from the example.
  2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 2/6] monitoring: Add user and group for " Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 3/6] services: monitoring: Use a log file for " Christopher Baines
@ 2020-11-28 12:11   ` Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 5/6] monitoring: Enable the Prometheus node exporter textfile collector Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 6/6] monitoring: Support extra options for the Prometheus node exporter Christopher Baines
  4 siblings, 0 replies; 9+ messages in thread
From: Christopher Baines @ 2020-11-28 12:11 UTC (permalink / raw)
  To: 44922

* doc/guix.texi (Prometheus Node Exporter Service): Simplify the example.
---
 doc/guix.texi | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index b0126b961d..ed41091cae 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21896,13 +21896,10 @@ where monitoring these statistics is desirable.
 @defvar {Scheme variable} prometheus-node-exporter-service-type
 This is the service type for the
 @uref{https://github.com/prometheus/node_exporter/, prometheus-node-exporter}
-service, its value must be a @code{prometheus-node-exporter-configuration}
-record as in this example:
+service, its value must be a @code{prometheus-node-exporter-configuration}.
 
 @lisp
-(service prometheus-node-exporter-service-type
-         (prometheus-node-exporter-configuration
-           (web-listen-address ":9100")))
+(service prometheus-node-exporter-service-type)
 @end lisp
 @end defvar
 
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [bug#44922] [PATCH 5/6] monitoring: Enable the Prometheus node exporter textfile collector.
  2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
                     ` (2 preceding siblings ...)
  2020-11-28 12:11   ` [bug#44922] [PATCH 4/6] doc: Remove redundant node exporter configuration from the example Christopher Baines
@ 2020-11-28 12:11   ` Christopher Baines
  2020-11-28 12:11   ` [bug#44922] [PATCH 6/6] monitoring: Support extra options for the Prometheus node exporter Christopher Baines
  4 siblings, 0 replies; 9+ messages in thread
From: Christopher Baines @ 2020-11-28 12:11 UTC (permalink / raw)
  To: 44922

* 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.
---
 doc/guix.texi               |  5 +++++
 gnu/services/monitoring.scm | 27 ++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index ed41091cae..6cd65b8739 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21913,6 +21913,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 239306fa39..c4bae229b8 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))))
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [bug#44922] [PATCH 6/6] monitoring: Support extra options for the Prometheus node exporter.
  2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
                     ` (3 preceding siblings ...)
  2020-11-28 12:11   ` [bug#44922] [PATCH 5/6] monitoring: Enable the Prometheus node exporter textfile collector Christopher Baines
@ 2020-11-28 12:11   ` Christopher Baines
  4 siblings, 0 replies; 9+ messages in thread
From: Christopher Baines @ 2020-11-28 12:11 UTC (permalink / raw)
  To: 44922

There are plenty of options supported that the Guix configuration record
doesn't help you with, so add this field to allow users to do their own thing.

* gnu/services/monitoring.scm (<prometheus-node-exporter-configuration>): Add
extra-options field.
(prometheus-node-exporter-shepherd-service): Handle the extra options.
* doc/guix.texi (Prometheus Node Exporter Service): Document this.
---
 doc/guix.texi               | 3 +++
 gnu/services/monitoring.scm | 9 ++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 6cd65b8739..dc624d89ec 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21918,6 +21918,9 @@ 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.
 
+@item @code{extra-options} (default: @code{'()})
+Extra options to pass to the Prometheus node exporter.
+
 @end table
 @end deftp
 
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index c4bae229b8..4b6f8ed623 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -128,7 +128,9 @@ HTTP.")
   (web-listen-address prometheus-node-exporter-web-listen-address
                       (default ":9100"))
   (textfile-directory prometheus-node-exporter-textfile-directory
-                      (default "/var/lib/prometheus/node-exporter")))
+                      (default "/var/lib/prometheus/node-exporter"))
+  (extra-options      prometheus-node-exporter-extra-options
+                      (default '())))
 
 (define %prometheus-node-exporter-accounts
   (list (user-account
@@ -145,7 +147,7 @@ HTTP.")
 (define prometheus-node-exporter-shepherd-service
   (match-lambda
     (( $ <prometheus-node-exporter-configuration>
-         package web-listen-address textfile-directory)
+         package web-listen-address textfile-directory extra-options)
      (list
       (shepherd-service
        (documentation "Prometheus node exporter.")
@@ -157,7 +159,8 @@ HTTP.")
                        #$@(if textfile-directory
                               (list "--collector.textfile.directory"
                                     textfile-directory)
-                              '()))
+                              '())
+                       #$@extra-options)
                  #:user "prometheus-node-exporter"
                  #:group "prometheus-node-exporter"
                  #:log-file "/var/log/prometheus-node-exporter.log"))
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements
  2020-11-28 12:04 [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements Christopher Baines
  2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
@ 2020-12-06 22:27 ` Ludovic Courtès
  2020-12-07  9:22   ` bug#44922: " Christopher Baines
  1 sibling, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2020-12-06 22:27 UTC (permalink / raw)
  To: Christopher Baines; +Cc: 44922

Hi,

Christopher Baines <mail@cbaines.net> skribis:

>   services: monitoring: Neaten up the Prometheus node exporter.
>   monitoring: Add user and group for the Prometheus node exporter.
>   services: monitoring: Use a log file for Prometheus node exporter.
>   doc: Remove redundant node exporter configuration from the example.
>   monitoring: Enable the Prometheus node exporter textfile collector.
>   monitoring: Support extra options for the Prometheus node exporter.
    ^
Should be “services: prometheus-node-exporter: …”.

Apart from that, on a quick look it LGTM.  Go for it!

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#44922: [PATCH 0/6] Prometheus node exporter service enhancements
  2020-12-06 22:27 ` [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements Ludovic Courtès
@ 2020-12-07  9:22   ` Christopher Baines
  0 siblings, 0 replies; 9+ messages in thread
From: Christopher Baines @ 2020-12-07  9:22 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 44922-done

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]


Ludovic Courtès <ludo@gnu.org> writes:

> Hi,
>
> Christopher Baines <mail@cbaines.net> skribis:
>
>>   services: monitoring: Neaten up the Prometheus node exporter.
>>   monitoring: Add user and group for the Prometheus node exporter.
>>   services: monitoring: Use a log file for Prometheus node exporter.
>>   doc: Remove redundant node exporter configuration from the example.
>>   monitoring: Enable the Prometheus node exporter textfile collector.
>>   monitoring: Support extra options for the Prometheus node exporter.
>     ^
> Should be “services: prometheus-node-exporter: …”.
>
> Apart from that, on a quick look it LGTM.  Go for it!

Great, I've pushed as 92f7c11af26580a7e6543efa94531652f187923a.

Thanks,

Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-07  9:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-28 12:04 [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements Christopher Baines
2020-11-28 12:11 ` [bug#44922] [PATCH 1/6] services: monitoring: Neaten up the Prometheus node exporter Christopher Baines
2020-11-28 12:11   ` [bug#44922] [PATCH 2/6] monitoring: Add user and group for " Christopher Baines
2020-11-28 12:11   ` [bug#44922] [PATCH 3/6] services: monitoring: Use a log file for " Christopher Baines
2020-11-28 12:11   ` [bug#44922] [PATCH 4/6] doc: Remove redundant node exporter configuration from the example Christopher Baines
2020-11-28 12:11   ` [bug#44922] [PATCH 5/6] monitoring: Enable the Prometheus node exporter textfile collector Christopher Baines
2020-11-28 12:11   ` [bug#44922] [PATCH 6/6] monitoring: Support extra options for the Prometheus node exporter Christopher Baines
2020-12-06 22:27 ` [bug#44922] [PATCH 0/6] Prometheus node exporter service enhancements Ludovic Courtès
2020-12-07  9:22   ` bug#44922: " Christopher Baines

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.