about summary refs log tree commit diff
path: root/modules/nixos
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2023-11-29 01:26:26 +0300
committerAzat Bahawi <azat@bahawi.net>2023-11-29 01:26:26 +0300
commit3c5d840e8d92aee25aa411fc2ab7f8881cfdfede (patch)
tree125bfef8f70b1e4c13cbcf975de3a942914f5d9b /modules/nixos
parent2023-11-28 (diff)
2023-11-29
Diffstat (limited to 'modules/nixos')
-rw-r--r--modules/nixos/loki.nix47
-rw-r--r--modules/nixos/monitoring/default.nix6
2 files changed, 40 insertions, 13 deletions
diff --git a/modules/nixos/loki.nix b/modules/nixos/loki.nix
index 49a9b19..0a92fbd 100644
--- a/modules/nixos/loki.nix
+++ b/modules/nixos/loki.nix
@@ -2,7 +2,6 @@
   config,
   lib,
   libNginx,
-  pkgs,
   ...
 }:
 with lib; let
@@ -42,21 +41,21 @@ in {
       configuration = rec {
         auth_enabled = false;
 
-        server = rec {
+        server = {
           http_listen_address = "127.0.0.1";
           http_listen_port = cfg.port;
 
           grpc_listen_address = "127.0.0.1";
-          grpc_listen_port = http_listen_port + 1;
+          grpc_listen_port = server.http_listen_port + 1;
 
           log_level = "warn";
         };
 
-        common = rec {
-          path_prefix = "/var/lib/loki";
+        common = {
+          path_prefix = config.services.loki.dataDir;
           storage.filesystem = {
-            chunks_directory = "${path_prefix}/chunks";
-            rules_directory = "${path_prefix}/rules";
+            chunks_directory = "${common.path_prefix}/chunks";
+            rules_directory = "${common.path_prefix}/rules";
           };
           replication_factor = 1;
           instance_interface_names = ["lo"];
@@ -66,20 +65,30 @@ in {
           };
         };
 
+        compactor = {
+          working_directory = "${common.path_prefix}/compactor";
+          retention_enabled = true;
+          retention_delete_delay = "1h";
+          retention_delete_worker_count = 64;
+        };
+
         ruler = {
-          rule_path = "${common.path_prefix}/ruler";
+          enable_api = true;
           storage = {
             type = "local";
-            local.directory =
-              pkgs.writeTextDir "ruler/ruler.yml"
-              (generators.toJSON {} {groups = [{name = "default";}];});
+            local.directory = common.storage.filesystem.rules_directory;
           };
         };
 
         limits_config = {
           max_streams_per_user = 0;
           max_global_streams_per_user = 0;
-          max_query_series = 100000; # Is this safe?
+          max_query_series = 4096;
+          retention_period = "720h";
+        };
+
+        cache_config = {
+          enable_fifocache = false;
         };
 
         schema_config.configs = [
@@ -97,6 +106,20 @@ in {
               period = "24h";
             };
           }
+          {
+            from = "2023-12-01";
+            store = "tsdb";
+            object_store = "filesystem";
+            schema = "v12";
+            index = {
+              prefix = "index_";
+              period = "24h";
+            };
+            chunks = {
+              prefix = "chunks_";
+              period = "24h";
+            };
+          }
         ];
 
         analytics.reporting_enabled = false;
diff --git a/modules/nixos/monitoring/default.nix b/modules/nixos/monitoring/default.nix
index a9b098b..cc06fbb 100644
--- a/modules/nixos/monitoring/default.nix
+++ b/modules/nixos/monitoring/default.nix
@@ -115,7 +115,11 @@ in {
         };
       };
 
-      loki.configuration.ruler.alertmanager_url = "https://${config.nixfiles.modules.alertmanager.domain}";
+      loki.configuration.ruler = {
+        external_url = "https://${config.nixfiles.modules.grafana.domain}";
+        alertmanager_url = "https://${config.nixfiles.modules.alertmanager.domain}";
+        enable_alertmanager_v2 = true;
+      };
 
       prometheus = {
         scrapeConfigs = with my.configurations;

Consider giving Nix/NixOS a try! <3