1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.org>
3 ;;; Copyright © 2018 Gábor Boskovits <boskovits@gmail.com>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu services monitoring)
21 #:use-module (gnu services)
22 #:use-module (gnu services shepherd)
23 #:use-module (gnu packages admin)
24 #:use-module (gnu packages monitoring)
25 #:use-module (gnu system shadow)
26 #:use-module (guix gexp)
27 #:use-module (guix records)
28 #:use-module (ice-9 match)
29 #:export (darkstat-configuration
30 prometheus-node-exporter-configuration
32 prometheus-node-exporter-service-type))
39 (define-record-type* <darkstat-configuration>
40 darkstat-configuration make-darkstat-configuration darkstat-configuration?
41 (package darkstat-configuration-package
43 (interface darkstat-configuration-interface)
44 (port darkstat-configuration-port
46 (bind-address darkstat-configuration-bind-address
47 (default "127.0.0.1"))
48 (base darkstat-configuration-base
51 (define %darkstat-accounts
56 (comment "darkstat daemon user")
57 (home-directory "/var/lib/darkstat")
58 (shell (file-append shadow "/sbin/nologin")))
63 (define darkstat-shepherd-service
65 (($ <darkstat-configuration>
66 package interface port bind-address base)
68 (documentation "Network statistics gatherer.")
69 (provision '(darkstat))
70 (requirement '(networking))
71 (start #~(make-forkexec-constructor
72 (list #$(file-append package "/sbin/darkstat")
77 "--syslog" "--no-daemon"
78 "--chroot" "/var/lib/darkstat"
80 "--import" "darkstat.db"
81 "--export" "darkstat.db")))
82 (stop #~(make-kill-destructor))))))
84 (define darkstat-service-type
88 "Run @command{darkstat} to serve network traffic statictics reports over
91 (list (service-extension account-service-type
92 (const %darkstat-accounts))
93 (service-extension shepherd-root-service-type
94 (compose list darkstat-shepherd-service))))))
96 (define-record-type* <prometheus-node-exporter-configuration>
97 prometheus-node-exporter-configuration
98 make-prometheus-node-exporter-configuration
99 prometheus-node-exporter-configuration?
100 (package prometheus-node-exporter-configuration-package
101 (default go-github-com-prometheus-node-exporter))
102 (web-listen-address prometheus-node-exporter-web-listen-address
105 (define prometheus-node-exporter-shepherd-service
107 (( $ <prometheus-node-exporter-configuration>
108 package web-listen-address)
110 (documentation "Prometheus node exporter.")
111 (provision '(prometheus-node-exporter))
112 (requirement '(networking))
113 (start #~(make-forkexec-constructor
114 (list #$(file-append package "/bin/node_exporter")
115 "--web.listen-address" #$web-listen-address)))
116 (stop #~(make-kill-destructor))))))
118 (define prometheus-node-exporter-service-type
120 (name 'prometheus-node-exporter)
122 "Run @command{node_exporter} to serve hardware and OS metrics to
125 (list (service-extension
126 shepherd-root-service-type
127 (compose list prometheus-node-exporter-shepherd-service))))))