Commit | Line | Data |
---|---|---|
693b52df SB |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.org> | |
a33652ee | 3 | ;;; Copyright © 2018 Gábor Boskovits <boskovits@gmail.com> |
693b52df SB |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
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. | |
11 | ;;; | |
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. | |
16 | ;;; | |
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/>. | |
19 | ||
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 | |
a33652ee GB |
30 | prometheus-node-exporter-configuration |
31 | darkstat-service-type | |
32 | prometheus-node-exporter-service-type)) | |
693b52df SB |
33 | |
34 | \f | |
35 | ;;; | |
36 | ;;; darkstat | |
37 | ;;; | |
38 | ||
39 | (define-record-type* <darkstat-configuration> | |
40 | darkstat-configuration make-darkstat-configuration darkstat-configuration? | |
41 | (package darkstat-configuration-package | |
42 | (default darkstat)) | |
43 | (interface darkstat-configuration-interface) | |
44 | (port darkstat-configuration-port | |
45 | (default "667")) | |
46 | (bind-address darkstat-configuration-bind-address | |
47 | (default "127.0.0.1")) | |
48 | (base darkstat-configuration-base | |
49 | (default "/"))) | |
50 | ||
51 | (define %darkstat-accounts | |
52 | (list (user-account | |
53 | (name "darkstat") | |
54 | (group "darkstat") | |
55 | (system? #t) | |
56 | (comment "darkstat daemon user") | |
57 | (home-directory "/var/lib/darkstat") | |
58 | (shell (file-append shadow "/sbin/nologin"))) | |
59 | (user-group | |
60 | (name "darkstat") | |
61 | (system? #t)))) | |
62 | ||
63 | (define darkstat-shepherd-service | |
64 | (match-lambda | |
65 | (($ <darkstat-configuration> | |
66 | package interface port bind-address base) | |
67 | (shepherd-service | |
68 | (documentation "Network statistics gatherer.") | |
69 | (provision '(darkstat)) | |
70 | (requirement '(networking)) | |
71 | (start #~(make-forkexec-constructor | |
72 | (list #$(file-append package "/sbin/darkstat") | |
73 | "-i" #$interface | |
74 | "-p" #$port | |
75 | "-b" #$bind-address | |
76 | "--base" #$base | |
77 | "--syslog" "--no-daemon" | |
78 | "--chroot" "/var/lib/darkstat" | |
79 | "--user" "darkstat" | |
80 | "--import" "darkstat.db" | |
81 | "--export" "darkstat.db"))) | |
82 | (stop #~(make-kill-destructor)))))) | |
83 | ||
84 | (define darkstat-service-type | |
85 | (service-type | |
86 | (name 'darkstat) | |
87 | (description | |
88 | "Run @command{darkstat} to serve network traffic statictics reports over | |
89 | HTTP.") | |
90 | (extensions | |
91 | (list (service-extension account-service-type | |
92 | (const %darkstat-accounts)) | |
93 | (service-extension shepherd-root-service-type | |
94 | (compose list darkstat-shepherd-service)))))) | |
a33652ee GB |
95 | |
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 | |
103 | (default ":9100"))) | |
104 | ||
105 | (define prometheus-node-exporter-shepherd-service | |
106 | (match-lambda | |
107 | (( $ <prometheus-node-exporter-configuration> | |
108 | package web-listen-address) | |
109 | (shepherd-service | |
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)))))) | |
117 | ||
118 | (define prometheus-node-exporter-service-type | |
119 | (service-type | |
120 | (name 'prometheus-node-exporter) | |
121 | (description | |
122 | "Run @command{node_exporter} to serve hardware and OS metrics to | |
123 | prometheus.") | |
124 | (extensions | |
125 | (list (service-extension | |
126 | shepherd-root-service-type | |
127 | (compose list prometheus-node-exporter-shepherd-service)))))) |