diff --git a/nixos/default.nix b/nixos/default.nix index 7dca1d6..fe0b97e 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -4,7 +4,6 @@ lib, primaryUser, isServer, - isDarwin, ... }: { @@ -84,18 +83,41 @@ }; services = { - prometheus.exporters.node = lib.mkIf (!isDarwin) { + prometheus.exporters.node = { enable = true; port = 9002; }; + alloy = { + enable = true; + extraFlags = [ "--stability.level=public-preview" ]; + configPath = pkgs.writeText "config.alloy" '' + loki.write "default" { + endpoint { + url = "http://192.168.2.30:3100/loki/api/v1/push" + } + } + + loki.source.journal "journal" { + forward_to = [loki.write.default.receiver] + labels = { + job = "systemd-journal", + host = sys.env("HOSTNAME"), + } + } + ''; + }; + gnome = lib.mkIf (!isServer) { tinysparql.enable = true; localsearch.enable = true; }; }; - networking.firewall.allowedTCPPorts = [ 9002 ]; + networking.firewall.allowedTCPPorts = [ + 9002 + 3100 + ]; users.users.${primaryUser} = { home = "/home/${primaryUser}"; diff --git a/nixos/roles/monitoring.nix b/nixos/roles/monitoring.nix index 20c5ac3..cc69dfd 100644 --- a/nixos/roles/monitoring.nix +++ b/nixos/roles/monitoring.nix @@ -39,6 +39,7 @@ in }; }; + # TODO: Computers should register themselves prometheus = { enable = true; port = 9001; @@ -61,10 +62,55 @@ in } ]; }; + + loki = { + enable = true; + configuration = { + auth_enabled = false; + server.http_listen_port = 3100; + ingester = { + lifecycler = { + address = "127.0.0.1"; + ring = { + kvstore.store = "inmemory"; + replication_factor = 1; + }; + }; + chunk_idle_period = "5m"; + chunk_retain_period = "30s"; + }; + schema_config.configs = [ + { + from = "2024-01-01"; + store = "tsdb"; + object_store = "filesystem"; + schema = "v13"; + index = { + prefix = "index_"; + period = "24h"; + }; + } + ]; + storage_config = { + tsdb_shipper = { + active_index_directory = "/var/lib/loki/tsdb-index"; + cache_location = "/var/lib/loki/tsdb-cache"; + }; + filesystem.directory = "/var/lib/loki/chunks"; + }; + limits_config = { + reject_old_samples = true; + reject_old_samples_max_age = "168h"; + }; + }; + }; }; networking.firewall.allowedTCPPorts = [ 80 + 443 + # TODO: Remove 9001 + 3100 ]; } diff --git a/nixos/sops.nix b/nixos/sops.nix index c4fd0e5..c274b11 100644 --- a/nixos/sops.nix +++ b/nixos/sops.nix @@ -7,6 +7,7 @@ secrets = { grafana_secret_key = { owner = "grafana"; + group = "grafana"; }; }; };