{ 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" ]) ; }; }