From 84f2cb5abe02f0c7212f39806a5ef457e4260e51 Mon Sep 17 00:00:00 2001 From: ktkk Date: Sat, 25 Oct 2025 22:39:05 +0000 Subject: [PATCH] Add Loki and Promtail to Grafana module I have no idea how this works --- modules/grafana/default.nix | 130 ++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/modules/grafana/default.nix b/modules/grafana/default.nix index 27671a3..6f94ec7 100644 --- a/modules/grafana/default.nix +++ b/modules/grafana/default.nix @@ -33,6 +33,11 @@ type = "prometheus"; url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}"; } + { + name = "Loki"; + type = "loki"; + url = "http://${config.services.loki.configuration.server.http_listen_address}:${toString config.services.loki.configuration.server.http_listen_port}"; + } ]; }; }; @@ -66,4 +71,129 @@ } ]; }; + + services.loki = { + enable = true; + + configuration = { + server = { + http_listen_port = 3100; + http_listen_address = "127.0.0.1"; + }; + + auth_enabled = false; + + common = { + instance_addr = "127.0.0.1"; + path_prefix = "/tmp/loki"; + storage = { + filesystem = { + chunks_directory = "/var/lib/loki/chunks"; + rules_directory = "/var/lib/loki/rules"; + }; + }; + replication_factor = 1; + ring = { + kvstore = { + store = "inmemory"; + }; + }; + }; + + ingester = { + lifecycler = { + address = "127.0.0.1"; + + ring = { + kvstore = { + store = "inmemory"; + }; + + replication_factor = 1; + }; + + final_sleep = "0s"; + }; + + chunk_idle_period = "1h"; + max_chunk_age = "1h"; + chunk_target_size = 1048576; + chunk_retain_period = "30s"; + }; + + schema_config = { + configs = [ + { + from = "2025-10-20"; + store = "tsdb"; + object_store = "filesystem"; + schema = "v13"; + index = { + prefix = "index_"; + period = "24h"; + }; + } + ]; + }; + + limits_config = { + reject_old_samples = true; + reject_old_samples_max_age = "168h"; + }; + + table_manager = { + retention_deletes_enabled = false; + retention_period = "0s"; + }; + + compactor = { + working_directory = "/var/lib/loki"; + compactor_ring = { + kvstore = { + store = "inmemory"; + }; + }; + }; + }; + }; + + services.promtail = { + enable = true; + + configuration = { + server = { + http_listen_port = 28183; + grpc_listen_port = 0; + }; + + positions = { + filename = "/tmp/positions.yaml"; + }; + + clients = [ + { + url = "http://127.0.0.1:${toString config.services.loki.configuration.server.http_listen_port}/loki/api/v1/push"; + } + ]; + + scrape_configs = [ + { + job_name = "journal"; + journal = { + max_age = "12h"; + labels = { + job = "systemd-journal"; + host = "homelab"; + }; + }; + relabel_configs = [ + { + source_labels = [ "__journal__systemd_unit" ]; + target_label = "unit"; + } + ]; + } + ]; + }; + }; }