diff --git a/modules/TLMS/default.nix b/modules/TLMS/default.nix index f82c7d8..33dc684 100644 --- a/modules/TLMS/default.nix +++ b/modules/TLMS/default.nix @@ -7,6 +7,6 @@ ./json.nix ./net.nix ./wg.nix - ./node-exporter.nix + ./monitoring.nix ]; } diff --git a/modules/TLMS/monitoring.nix b/modules/TLMS/monitoring.nix new file mode 100644 index 0000000..8e47f31 --- /dev/null +++ b/modules/TLMS/monitoring.nix @@ -0,0 +1,45 @@ +{ lib, config, ... }: +let + cfg = config.deployment-TLMS.monitoring; +in +{ + options.deployment-TLMS.monitoring = with lib; { + enable = mkOption { + type = types.bool; + default = true; + description = '' + Whether to enable TLMS default prometheus exporter and log collection + ''; + }; + monitoring.node-exporter = with lib; { + port = mkOption { + type = types.port; + default = 8119; + description = '' + Default port for prometheus node exporter to listen to + ''; + }; + }; + }; + + config = + let + wg-addr-pred = !isNull config.deployment-TLMS.net.wg.addr4; + check-wg = enabled: + lib.assertMsg (enabled && wg-addr-pred) + ''For monitoring to be working the system must be in wireguard. See config.deplayment-TLMS.net.wg''; + in + lib.mkIf (check-wg cfg.enable) { + # prometheus node exporter + services.prometheus.exporters = { + node = { + enable = true; + port = 8119; + listenAddress = config.deployment-TLMS.net.wg.addr4; + enabledCollectors = [ + "systemd" + ]; + }; + }; + }; +} diff --git a/modules/TLMS/node-exporter.nix b/modules/TLMS/node-exporter.nix deleted file mode 100644 index 753cd53..0000000 --- a/modules/TLMS/node-exporter.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ config, ... }: -{ - # metrics exporter - services.prometheus.exporters = { - node = { - enable = true; - port = 8119; - listenAddress = config.deployment-TLMS.net.wg.addr4; - enabledCollectors = [ - "systemd" - ]; - }; - }; -}