diff --git a/machines/modules/malobeo/metrics.nix b/machines/modules/malobeo/metrics.nix new file mode 100644 index 00000000..c5f320b4 --- /dev/null +++ b/machines/modules/malobeo/metrics.nix @@ -0,0 +1,56 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.malobeo.metrics; +in +{ + options.malobeo.metrics = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable sharing metrics"; + }; + enablePromtail = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable sharing logs"; + }; + logNginx = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Share nginx logs"; + }; + lokiHost = lib.mkOption { + type = lib.types.str; + default = "10.0.0.14"; + description = "Address of loki host"; + }; + }; + + config = lib.mkIf (cfg.enable) { + + networking.firewall.allowedTCPPorts = [ 9002 ]; + + services.prometheus = { + exporters = { + node = { + enable = true; + enabledCollectors = [ "systemd" "processes" ]; + port = 9002; + }; + }; + }; + + services.promtail = { + enable = cfg.enablePromtail; + configFile = import ./promtail_config.nix { + lokiAddress = cfg.lokiHost; + logNginx = cfg.logNginx; + config = config; + pkgs = pkgs; + }; + }; + + users.users.promtail.extraGroups = [ "systemd-journal" ] ++ (lib.optionals cfg.logNginx [ "nginx" ]) ; + + }; +} diff --git a/outputs.nix b/outputs.nix index 72176b3a..9cfbf03b 100644 --- a/outputs.nix +++ b/outputs.nix @@ -240,6 +240,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems microvm.imports = [ ./machines/modules/malobeo/microvm_host.nix ]; vpn.imports = [ ./machines/modules/malobeo/wireguard.nix ]; initssh.imports = [ ./machines/modules/malobeo/initssh.nix ]; + metrics.imports = [ ./machines/modules/malobeo/metrics.nix ]; disko.imports = [ ./machines/modules/disko ]; };