git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/prometheus/exporters/knot: init
commitb4bd584b640d0bee0ab5a2d8dbbaf4f5e4ee53db authorMaximilian Bosch <maximilian@mbosch.me> dateFri 5 Mar 2021, 13:06 (6 years ago) parentbae2759
3 files changed+69
nixos/modules/services/monitoring/prometheus/exporters.nix+1 nixos/modules/services/monitoring/prometheus/exporters/knot.nix+50 nixos/tests/prometheus-exporters.nix+18
nixos/modules/services/monitoring/prometheus/exporters.nix+1
@@ -31,6 +31,7 @@ let
3131 "fritzbox"
3232 "json"
3333 "keylight"
34+ "knot"
3435 "lnd"
3536 "mail"
3637 "mikrotik"
nixos/modules/services/monitoring/prometheus/exporters/knot.nixnew file+50
@@ -0,0 +1,50 @@
1+{ config, lib, pkgs, options }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.prometheus.exporters.knot;
7+in {
8+ port = 9433;
9+ extraOpts = {
10+ knotLibraryPath = mkOption {
11+ type = types.str;
12+ default = "${pkgs.knot-dns.out}/lib/libknot.so";
13+ defaultText = "\${pkgs.knot-dns}/lib/libknot.so";
14+ description = ''
15+ Path to the library of <package>knot-dns</package>.
16+ '';
17+ };
18+
19+ knotSocketPath = mkOption {
20+ type = types.str;
21+ default = "/run/knot/knot.sock";
22+ description = ''
23+ Socket path of <citerefentry><refentrytitle>knotd</refentrytitle>
24+ <manvolnum>8</manvolnum></citerefentry>.
25+ '';
26+ };
27+
28+ knotSocketTimeout = mkOption {
29+ type = types.int;
30+ default = 2000;
31+ description = ''
32+ Timeout in seconds.
33+ '';
34+ };
35+ };
36+ serviceOpts = {
37+ serviceConfig = {
38+ ExecStart = ''
39+ ${pkgs.prometheus-knot-exporter}/bin/knot_exporter \
40+ --web-listen-addr ${cfg.listenAddress} \
41+ --web-listen-port ${toString cfg.port} \
42+ --knot-library-path ${cfg.knotLibraryPath} \
43+ --knot-socket-path ${cfg.knotSocketPath} \
44+ --knot-socket-timeout ${toString cfg.knotSocketTimeout} \
45+ ${concatStringsSep " \\\n " cfg.extraFlags}
46+ '';
47+ SupplementaryGroups = [ "knot" ];
48+ };
49+ };
50+}
nixos/tests/prometheus-exporters.nix+18
@@ -248,6 +248,24 @@ let
248248 '';
249249 };
250250
251+ knot = {
252+ exporterConfig = {
253+ enable = true;
254+ };
255+ metricProvider = {
256+ services.knot = {
257+ enable = true;
258+ extraArgs = [ "-v" ];
259+ };
260+ };
261+ exporterTest = ''
262+ wait_for_unit("knot.service")
263+ wait_for_unit("prometheus-knot-exporter.service")
264+ wait_for_open_port(9433)
265+ succeed("curl -sSf 'localhost:9433' | grep -q 'knot_server_zone_count 0.0'")
266+ '';
267+ };
268+
251269 keylight = {
252270 # A hardware device is required to properly test this exporter, so just
253271 # perform a couple of basic sanity checks that the exporter is running