diff --git a/config/default.nix b/config/default.nix index fdc51e40..bb46f028 100644 --- a/config/default.nix +++ b/config/default.nix @@ -5,10 +5,10 @@ ./nix.nix ./sops.nix ./wireguard.nix - ./services/loki.nix ./home.nix ./services/restic.nix ./specialization.nix + ./services/promtail.nix ]; services.openssh.enable = true; environment.systemPackages = with pkgs; [ git pinentry-curses ]; diff --git a/config/nixos-8gb-fsn1-1.nix b/config/nixos-8gb-fsn1-1.nix index e8d04a22..ed811b4a 100644 --- a/config/nixos-8gb-fsn1-1.nix +++ b/config/nixos-8gb-fsn1-1.nix @@ -20,6 +20,7 @@ ./services/minecraft.nix ./services/nix-cache.nix ./services/minio.nix + ./services/loki.nix ]; boot.initrd.availableKernelModules = [ "ata_piix" "virtio_pci" "virtio_scsi" "xhci_pci" "sd_mod" "sr_mod" ]; diff --git a/config/services/loki.nix b/config/services/loki.nix index c40e580f..12db586b 100644 --- a/config/services/loki.nix +++ b/config/services/loki.nix @@ -1,19 +1,8 @@ -{ pkgs, ... }: - +{ ... }: { services.loki = { enable = true; configFile = ./loki.yaml; }; - systemd.services.promtail = { - description = "Promtail service for Loki"; - wantedBy = [ "multi-user.target" ]; - - serviceConfig = { - ExecStart = '' - ${pkgs.grafana-loki}/bin/promtail --config.file ${./promtrail.yaml} - ''; - }; - }; networking.firewall.interfaces."wg0".allowedTCPPorts = [ 3100 ]; } diff --git a/config/services/promtail.nix b/config/services/promtail.nix new file mode 100644 index 00000000..6a83a812 --- /dev/null +++ b/config/services/promtail.nix @@ -0,0 +1,42 @@ +{ config, pkgs, lib, ... }: +let promtail_config = { + server = { + http_listen_port = 28183; + grpc_listen_port = 0; + }; + positions = { + filename = "/tmp/positions.yaml"; + }; + client = { + url = "http://[fd0d:a262:1fa6:e621:b4e1:08ff:e658:6f49]:3100/loki/api/v1/push"; + external_labels.host = config.networking.hostName; + }; + scrapeConfigs = [ + { + job_name = "journal"; + journal = { + max_age = "12h"; + labels.job = "systemd-journal"; + }; + relabel_configs = [ + { + source_labels = [ "__journal__systemd_unit" ]; + target_label = "unit"; + } + ]; + } + ]; +}; +in +{ + systemd.services.promtail = { + description = "Promtail service for Loki"; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = '' + ${pkgs.grafana-loki}/bin/promtail --config.file ${lib.generators.toYAML ./promtrail.yaml} + ''; + }; + }; +} diff --git a/config/services/promtrail.yaml b/config/services/promtrail.yaml deleted file mode 100644 index 5db22360..00000000 --- a/config/services/promtrail.yaml +++ /dev/null @@ -1,24 +0,0 @@ -server: - http_listen_port: 28183 - grpc_listen_port: 0 - -positions: - filename: /tmp/positions.yaml - -clients: - - url: http://[fd0d:a262:1fa6:e621:b4e1:08ff:e658:6f49]:3100/loki/api/v1/push - external_labels: - host: nixos-8gb-fsn1-1 - - url: http://[fd0d:a262:1fa6:e621:47e6:24d4:2acb:9437]:3100/loki/api/v1/push - external_labels: - host: nutty-noon - -scrape_configs: - - job_name: journal - journal: - max_age: 12h - labels: - job: systemd-journal - relabel_configs: - - source_labels: ["__journal__systemd_unit"] - target_label: "unit"