From patchwork Mon Apr 20 21:17:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 21369 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6181C27BBE4; Mon, 20 Apr 2020 22:18:10 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 2C86427BBE1 for ; Mon, 20 Apr 2020 22:18:10 +0100 (BST) Received: from localhost ([::1]:42484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnt-00044z-KE for patchwork@mira.cbaines.net; Mon, 20 Apr 2020 17:18:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41352) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnm-00044X-IM for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQdnm-0000Pw-0u for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37001) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQdnl-0000Pr-M9 for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQdnl-0002ft-HO for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40738] [PATCH 1/4] gnu: Add prometheus. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 20 Apr 2020 21:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40738 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo To: 40738@debbugs.gnu.org Received: via spool by 40738-submit@debbugs.gnu.org id=B40738.158741746710220 (code B ref 40738); Mon, 20 Apr 2020 21:18:01 +0000 Received: (at 40738) by debbugs.gnu.org; 20 Apr 2020 21:17:47 +0000 Received: from localhost ([127.0.0.1]:48532 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnX-0002ef-7y for submit@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:47 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33670) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnW-0002eJ-7Y for 40738@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:46 -0400 Received: from localhost (unknown [46.237.173.52]) by mira.cbaines.net (Postfix) with ESMTPSA id A354E27BBE1 for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 22:17:45 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 8b41547d for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 21:17:43 +0000 (UTC) From: Christopher Baines Date: Mon, 20 Apr 2020 22:17:40 +0100 Message-Id: <20200420211743.23476-1-mail@cbaines.net> X-Mailer: git-send-email 2.26.0 In-Reply-To: <87v9lt50d4.fsf@cbaines.net> References: <87v9lt50d4.fsf@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/monitoring.scm (prometheus): New variable. --- gnu/packages/monitoring.scm | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gnu/packages/monitoring.scm b/gnu/packages/monitoring.scm index 8da31d6a84..345c2c16c5 100644 --- a/gnu/packages/monitoring.scm +++ b/gnu/packages/monitoring.scm @@ -422,6 +422,55 @@ written in Go with pluggable metric collectors.") (home-page "https://github.com/prometheus/node_exporter") (license license:asl2.0))) +(define-public prometheus + (package + (name "prometheus") + (version "2.17.1") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/prometheus/prometheus.git") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "1r7zpq6647lrm7cmid6nnf2xnljqh1i9g0fxvs0qrfd2sxxgj0c7")))) + (build-system go-build-system) + (arguments + '(#:unpack-path "github.com/prometheus/prometheus" + #:import-path "github.com/prometheus/prometheus/cmd/prometheus" + #:install-source? #f + #:phases + (modify-phases %standard-phases + (add-after 'unpack 'patch + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (assets-prefix + (string-append out "/var/lib/prometheus/assets"))) + (substitute* "src/github.com/prometheus/prometheus/web/ui/ui.go" + (("var assetsPrefix string") + (string-append "var assetsPrefix string = \"" + assets-prefix + "\"")))) + #t)) + (add-after 'install 'install-assets + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (assets-prefix + (string-append out "/var/lib/prometheus/assets"))) + (for-each (lambda (directory) + (copy-recursively + (string-append "src/github.com/prometheus/prometheus" + "/web/ui/" directory) + (string-append assets-prefix + "/" directory))) + '("static" "templates"))) + #t))))) + (home-page "https://prometheus.io/") + (synopsis "") + (description "") + (license ""))) + (define-public fswatch (package (name "fswatch") From patchwork Mon Apr 20 21:17:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 21372 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 131CF27BBE4; Mon, 20 Apr 2020 22:18:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id AE78227BBE1 for ; Mon, 20 Apr 2020 22:18:14 +0100 (BST) Received: from localhost ([::1]:42490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdny-00048k-7v for patchwork@mira.cbaines.net; Mon, 20 Apr 2020 17:18:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41360) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnn-00044d-2H for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQdnm-0000Q6-GK for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQdnm-0000Q1-2v for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQdnl-0002g0-TQ for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40738] [PATCH 2/4] services: Add a Prometheus service. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 20 Apr 2020 21:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40738 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo To: 40738@debbugs.gnu.org Received: via spool by 40738-submit@debbugs.gnu.org id=B40738.158741746810226 (code B ref 40738); Mon, 20 Apr 2020 21:18:01 +0000 Received: (at 40738) by debbugs.gnu.org; 20 Apr 2020 21:17:48 +0000 Received: from localhost ([127.0.0.1]:48534 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnX-0002en-Ri for submit@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:48 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33672) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnW-0002eK-81 for 40738@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:46 -0400 Received: from localhost (unknown [46.237.173.52]) by mira.cbaines.net (Postfix) with ESMTPSA id B9D0727BBE4 for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 22:17:45 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 95aadcd5 for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 21:17:43 +0000 (UTC) From: Christopher Baines Date: Mon, 20 Apr 2020 22:17:41 +0100 Message-Id: <20200420211743.23476-2-mail@cbaines.net> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200420211743.23476-1-mail@cbaines.net> References: <87v9lt50d4.fsf@cbaines.net> <20200420211743.23476-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches --- gnu/services/monitoring.scm | 82 +++++++++++++++++++++++++++++++++++++ gnu/tests/monitoring.scm | 73 ++++++++++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 1 deletion(-) 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 @@ -40,6 +40,17 @@ darkstat-service-type prometheus-node-exporter-service-type + prometheus-service-type + + 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)))))) + +;;; +;;; Prometheus +;;; + +(define-record-type* + prometheus-configuration + make-prometheus-configuration + prometheus-configuration? + (package prometheus-configuration-package + (default prometheus)) + (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 + (default '()))) + +(define prometheus-shepherd-service + (match-lambda + (($ package user group + config-file web-listen-address + storage-tsdb-path extra-options) + (shepherd-service + (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 + #$@extra-options) + #:user #$user + #:group #$group + #:log-file "/var/log/prometheus.log")) + (stop #~(make-kill-destructor)))))) + +(define (prometheus-account config) + (match-record config + (user group) + (list (user-group + (name group) + (system? #t)) + (user-account + (name user) + (group group) + (system? #t) + (comment "Prometheus user") + (home-directory "/var/lib/prometheus") + (shell (file-append shadow "/sbin/nologin")))))) + +(define prometheus-service-type + (service-type + (name 'prometheus) + (description + "Run @command{prometheus} to scrape targets for mertrics and provide the +web interface.") + (extensions + (list (service-extension shepherd-root-service-type + (compose list prometheus-shepherd-service)) + (service-extension account-service-type + prometheus-account))) + (default-value (prometheus-configuration)))) + (define-record-type* 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 @@ -31,9 +31,80 @@ #:use-module (gnu system) #:use-module (gnu tests) #:use-module (guix gexp) - #:export (%test-prometheus-node-exporter + #:export (%test-prometheus + %test-prometheus-node-exporter %test-zabbix)) + +;;; +;;; Prometheus +;;; + +(define* (run-prometheus-test name test-os) + "Run tests in %TEST-OS, which has Prometheus running." + (define os + (marionette-operating-system + test-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine + (operating-system os) + (port-forwardings '((8080 . 9090))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-11) + (srfi srfi-64) + (gnu build marionette) + (web client) + (web response)) + + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin #$name) + + (test-assert "prometheus running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'prometheus) + (#f #f) + (('service response-parts ...) + (match (assq-ref response-parts 'running) + ((pid) (number? pid)))))) + marionette)) + + (test-equal "prometheus healthy" + 200 + (begin + (wait-for-tcp-port 9090 marionette) + (let-values (((response text) + (http-get "http://localhost:8080/-/healthy"))) + (response-code response)))) + + (test-end) + (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 + (system-test + (name "prometheus") + (description "Connect to a running Prometheus service.") + (value (run-prometheus-test name + %prometheus-test-os)))) + ;;; ;;; Prometheus Node Exporter From patchwork Mon Apr 20 21:17:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 21370 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 4C94527BBE4; Mon, 20 Apr 2020 22:18:11 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 051ED27BBE1 for ; Mon, 20 Apr 2020 22:18:11 +0100 (BST) Received: from localhost ([::1]:42486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnu-00045n-ID for patchwork@mira.cbaines.net; Mon, 20 Apr 2020 17:18:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41366) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnn-00044e-Fp for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQdnm-0000QP-Qf for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQdnm-0000QF-Ek for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQdnm-0002g8-AC for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40738] [PATCH 3/4] gnu: Add alertmanager. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 20 Apr 2020 21:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40738 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo To: 40738@debbugs.gnu.org Received: via spool by 40738-submit@debbugs.gnu.org id=B40738.158741747110240 (code B ref 40738); Mon, 20 Apr 2020 21:18:02 +0000 Received: (at 40738) by debbugs.gnu.org; 20 Apr 2020 21:17:51 +0000 Received: from localhost ([127.0.0.1]:48536 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnb-0002f5-8j for submit@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:51 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33674) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnW-0002eL-9i for 40738@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:47 -0400 Received: from localhost (unknown [46.237.173.52]) by mira.cbaines.net (Postfix) with ESMTPSA id D5F9127BBEA for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 22:17:45 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 66be6fc9 for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 21:17:43 +0000 (UTC) From: Christopher Baines Date: Mon, 20 Apr 2020 22:17:42 +0100 Message-Id: <20200420211743.23476-3-mail@cbaines.net> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200420211743.23476-1-mail@cbaines.net> References: <87v9lt50d4.fsf@cbaines.net> <20200420211743.23476-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/monitoring.scm (alertmanager): New variable. --- gnu/packages/monitoring.scm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gnu/packages/monitoring.scm b/gnu/packages/monitoring.scm index 345c2c16c5..e0e345d259 100644 --- a/gnu/packages/monitoring.scm +++ b/gnu/packages/monitoring.scm @@ -471,6 +471,29 @@ written in Go with pluggable metric collectors.") (description "") (license ""))) +(define-public alertmanager + (package + (name "alertmanager") + (version "0.20.0") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/prometheus/alertmanager.git") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "1bq6vbpy25k7apvs2ga3fbp1cbnv9j0y1g1khvz2qgz6a2zvhgg3")))) + (build-system go-build-system) + (arguments + '(#:unpack-path "github.com/prometheus/alertmanager" + #:import-path "github.com/prometheus/alertmanager/cmd/alertmanager" + #:install-source? #f)) + (home-page "https://prometheus.io/") + (synopsis "") + (description "") + (license ""))) + (define-public fswatch (package (name "fswatch") From patchwork Mon Apr 20 21:17:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 21371 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 915D527BBE4; Mon, 20 Apr 2020 22:18:13 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 38C3D27BBE1 for ; Mon, 20 Apr 2020 22:18:13 +0100 (BST) Received: from localhost ([::1]:42488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnw-00046t-Mg for patchwork@mira.cbaines.net; Mon, 20 Apr 2020 17:18:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41370) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnn-00044i-RV for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQdnn-0000Qh-7n for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQdnm-0000QW-RP for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQdnm-0002gF-MF for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40738] [PATCH 4/4] services: Add a service for Alertmanager. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 20 Apr 2020 21:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40738 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo To: 40738@debbugs.gnu.org Received: via spool by 40738-submit@debbugs.gnu.org id=B40738.158741747110246 (code B ref 40738); Mon, 20 Apr 2020 21:18:02 +0000 Received: (at 40738) by debbugs.gnu.org; 20 Apr 2020 21:17:51 +0000 Received: from localhost ([127.0.0.1]:48538 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnb-0002f7-FB for submit@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:51 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33676) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnW-0002eM-DG for 40738@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:47 -0400 Received: from localhost (unknown [46.237.173.52]) by mira.cbaines.net (Postfix) with ESMTPSA id F0D3927BBEB for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 22:17:45 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id a4197032 for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 21:17:43 +0000 (UTC) From: Christopher Baines Date: Mon, 20 Apr 2020 22:17:43 +0100 Message-Id: <20200420211743.23476-4-mail@cbaines.net> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200420211743.23476-1-mail@cbaines.net> References: <87v9lt50d4.fsf@cbaines.net> <20200420211743.23476-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches --- gnu/services/monitoring.scm | 82 +++++++++++++++++++++++++++++++++++++ gnu/tests/monitoring.scm | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm index a37dfd80d8..50a4b7302c 100644 --- a/gnu/services/monitoring.scm +++ b/gnu/services/monitoring.scm @@ -51,6 +51,17 @@ prometheus-configuration-storage-tsdb-path prometheus-configuration-extra-options + alertmanager-service-type + + alertmanager-configuration + alertmanager-configuration-package + alertmanager-configuration-user + alertmanager-configuration-group + alertmanager-configuration-config-file + alertmanager-configuration-web-listen-address + alertmanager-configuration-storage-path + alertmanager-configuration-extra-options + zabbix-server-configuration zabbix-server-service-type zabbix-agent-configuration @@ -226,6 +237,77 @@ prometheus.") (compose list prometheus-node-exporter-shepherd-service)))) (default-value (prometheus-node-exporter-configuration)))) + +;;; +;;; Alertmanager +;;; + +(define-record-type* + alertmanager-configuration + make-alertmanager-configuration + alertmanager-configuration? + (package alertmanager-configuration-package + (default alertmanager)) + (user alertmanager-configuration-user + (default "alertmanager")) + (group alertmanagerconfiguration-group + (default "alertmanager")) + (config-file alertmanager-config-file + (default (plain-file "alertmanager.yml" ""))) + (web-listen-address alertmanager-web-listen-address + (default ":9093")) + (storage-tsdb-path alertmanager-storage-tsdb-path + (default "/var/lib/alertmanager/data/")) + (extra-options alertmanager-configuration-extra-options + (default '()))) + +(define alertmanager-shepherd-service + (match-lambda + (($ package user group + config-file web-listen-address + storage-tsdb-path extra-options) + (shepherd-service + (documentation "Alertmanager monitoring system and time series database.") + (provision '(alertmanager)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/bin/alertmanager") + "--config.file" #$config-file + "--web.listen-address" #$web-listen-address + "--storage.path" #$storage-tsdb-path + #$@extra-options) + #:user #$user + #:group #$group + #:log-file "/var/log/alertmanager.log")) + (stop #~(make-kill-destructor)))))) + +(define (alertmanager-account config) + (match-record config + (user group) + (list (user-group + (name group) + (system? #t)) + (user-account + (name user) + (group group) + (system? #t) + (comment "Alertmanager user") + (home-directory "/var/lib/alertmanager") + (shell (file-append shadow "/sbin/nologin")))))) + +(define alertmanager-service-type + (service-type + (name 'alertmanager) + (description + "Run @command{alertmanager} to scrape targets for mertrics and provide the +web interface.") + (extensions + (list (service-extension shepherd-root-service-type + (compose list alertmanager-shepherd-service)) + (service-extension account-service-type + alertmanager-account))) + (default-value (alertmanager-configuration)))) + ;;; ;;; Zabbix server diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm index e8c0847229..b77b654abc 100644 --- a/gnu/tests/monitoring.scm +++ b/gnu/tests/monitoring.scm @@ -33,6 +33,7 @@ #:use-module (guix gexp) #:export (%test-prometheus %test-prometheus-node-exporter + %test-alertmanager %test-zabbix)) @@ -176,6 +177,76 @@ (value (run-prometheus-node-exporter-server-test name %prometheus-node-exporter-os)))) + +;;; +;;; Alertmanager +;;; + +(define* (run-alertmanager-test name test-os) + "Run tests in %TEST-OS, which has Alertmanager running." + (define os + (marionette-operating-system + test-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine + (operating-system os) + (port-forwardings '((8080 . 9093))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-11) + (srfi srfi-64) + (gnu build marionette) + (web client) + (web response)) + + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin #$name) + + (test-assert "alertmanager running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'alertmanager) + (#f #f) + (('service response-parts ...) + (match (assq-ref response-parts 'running) + ((pid) (number? pid)))))) + marionette)) + + (test-equal "alertmanager healthy" + 200 + (begin + (wait-for-tcp-port 9090 marionette) + (let-values (((response text) + (http-get "http://localhost:8080/-/healthy"))) + (response-code response)))) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation (string-append name "-test") test)) + +(define %alertmanager-test-os + (simple-operating-system + (service dhcp-client-service-type) + (service alertmanager-service-type))) + +(define %test-alertmanager + (system-test + (name "alertmanager") + (description "Connect to a running Alertmanager service.") + (value (run-alertmanager-test name + %alertmanager-test-os)))) + ;;; ;;; Zabbix