gnu/services/monitoring.scm | 82 +++++++++++++++++++++++++++++++++++++
gnu/tests/monitoring.scm | 73 ++++++++++++++++++++++++++++++++-
2 files changed, 154 insertions(+), 1 deletion(-)
Toggle diff (188 lines)
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index 511f4fb2fe..a37dfd80d8 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
prometheus-node-exporter-service-type
+ prometheus-service-type
+ <prometheus-configuration>
+ prometheus-configuration
+ prometheus-configuration-package
+ prometheus-configuration-user
+ prometheus-configuration-group
+ prometheus-configuration-config-file
+ prometheus-configuration-web-listen-address
+ prometheus-configuration-storage-tsdb-path
+ prometheus-configuration-extra-options
zabbix-server-configuration
zabbix-server-service-type
zabbix-agent-configuration
@@ -110,6 +121,77 @@ HTTP.")
(service-extension shepherd-root-service-type
(compose list darkstat-shepherd-service))))))
+(define-record-type* <prometheus-configuration>
+ prometheus-configuration
+ make-prometheus-configuration
+ prometheus-configuration?
+ (package prometheus-configuration-package
+ (user prometheus-configuration-user
+ (default "prometheus"))
+ (group prometheusconfiguration-group
+ (default "prometheus"))
+ (config-file prometheus-config-file
+ (default (plain-file "prometheus.yml" "")))
+ (web-listen-address prometheus-web-listen-address
+ (default "0.0.0.0:9090"))
+ (storage-tsdb-path prometheus-storage-tsdb-path
+ (default "/var/lib/prometheus/data/"))
+ (extra-options prometheus-configuration-extra-options
+(define prometheus-shepherd-service
+ (($ <prometheus-configuration> package user group
+ config-file web-listen-address
+ storage-tsdb-path extra-options)
+ (documentation "Prometheus monitoring system and time series database.")
+ (provision '(prometheus))
+ (requirement '(networking))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append package "/bin/prometheus")
+ "--config.file" #$config-file
+ "--web.listen-address" #$web-listen-address
+ "--storage.tsdb.path" #$storage-tsdb-path
+ #:log-file "/var/log/prometheus.log"))
+ (stop #~(make-kill-destructor))))))
+(define (prometheus-account config)
+ (match-record config <prometheus-configuration>
+ (comment "Prometheus user")
+ (home-directory "/var/lib/prometheus")
+ (shell (file-append shadow "/sbin/nologin"))))))
+(define prometheus-service-type
+ "Run @command{prometheus} to scrape targets for mertrics and provide the
+ (list (service-extension shepherd-root-service-type
+ (compose list prometheus-shepherd-service))
+ (service-extension account-service-type
+ (default-value (prometheus-configuration))))
(define-record-type* <prometheus-node-exporter-configuration>
prometheus-node-exporter-configuration
make-prometheus-node-exporter-configuration
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index 732fbc54d7..e8c0847229 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
#:use-module (gnu system)
- #:export (%test-prometheus-node-exporter
+ #:export (%test-prometheus
+ %test-prometheus-node-exporter
+(define* (run-prometheus-test name test-os)
+ "Run tests in %TEST-OS, which has Prometheus running."
+ (marionette-operating-system
+ #:imported-modules '((gnu services herd))))
+ (port-forwardings '((8080 . 9090)))))
+ (with-imported-modules '((gnu build marionette))
+ (use-modules (srfi srfi-11)
+ (make-marionette (list #$vm)))
+ (test-assert "prometheus running"
+ (use-modules (gnu services herd))
+ (match (start-service 'prometheus)
+ (('service response-parts ...)
+ (match (assq-ref response-parts 'running)
+ ((pid) (number? pid))))))
+ (test-equal "prometheus healthy"
+ (wait-for-tcp-port 9090 marionette)
+ (let-values (((response text)
+ (http-get "http://localhost:8080/-/healthy")))
+ (response-code response))))
+ (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+ (gexp->derivation (string-append name "-test") test))
+(define %prometheus-test-os
+ (simple-operating-system
+ (service dhcp-client-service-type)
+ (service prometheus-service-type)))
+(define %test-prometheus
+ (description "Connect to a running Prometheus service.")
+ (value (run-prometheus-test name
+ %prometheus-test-os))))
;;; Prometheus Node Exporter