about summary refs log tree commit diff
path: root/modules/nixos/promtail.nix
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2023-05-21 23:10:32 +0300
committerAzat Bahawi <azat@bahawi.net>2023-05-21 23:10:32 +0300
commitb07e10139c88d6060e57ca52b2dc12b17b53ac82 (patch)
tree5b5cddc2f47bddb8e8914aa66ae18d52cd519965 /modules/nixos/promtail.nix
parent2023-05-06 (diff)
2023-05-21
Diffstat (limited to '')
-rw-r--r--modules/nixos/promtail.nix41
1 files changed, 20 insertions, 21 deletions
diff --git a/modules/nixos/promtail.nix b/modules/nixos/promtail.nix
index d52384a..157eb72 100644
--- a/modules/nixos/promtail.nix
+++ b/modules/nixos/promtail.nix
@@ -21,6 +21,12 @@ in {
       type = with types; str;
       default = "https://${config.nixfiles.modules.loki.domain}";
     };
+
+    filters = mkOption {
+      description = ''Filters to use with "scrape_config.pipeline_stages".'';
+      type = with types; listOf attrs;
+      default = [];
+    };
   };
 
   config = mkIf cfg.enable {
@@ -56,7 +62,7 @@ in {
         scrape_configs = [
           {
             job_name = "journal";
-            journal.max_age = "12h";
+            journal.max_age = "24h";
             relabel_configs =
               map (n: let
                 label = toLower n;
@@ -74,12 +80,12 @@ in {
 
                 "MESSAGE"
                 # "MESSAGE_ID"
-                # "PRIORITY"
+                "PRIORITY"
                 # "CODE_FILE"
                 # "CODE_LINE"
                 # "CODE_FUNC"
                 # "ERRNO"
-                # "SYSLOG_FACILITY"
+                "SYSLOG_FACILITY"
                 "SYSLOG_IDENTIFIER"
                 # "SYSLOG_PID"
                 # "_PID"
@@ -93,8 +99,8 @@ in {
                 # "_AUDIT_LOGINUID"
                 # "_SYSTEMD_CGROUP"
                 # "_SYSTEMD_SESSION"
-                "_SYSTEMD_UNIT"
-                "_SYSTEMD_USER_UNIT"
+                # "_SYSTEMD_UNIT"
+                # "_SYSTEMD_USER_UNIT"
                 # "_SYSTEMD_OWNER_UID"
                 # "_SYSTEMD_SLICE"
                 # "_SELINUX_CONTEXT"
@@ -106,23 +112,16 @@ in {
                 # "__CURSOR"
                 # "__REALTIME_TIMESTAMP"
                 # "__MONOTONIC_TIMESTAMP"
+              ]
+              ++ [
+                {
+                  # This is weird. I can't find where is this defined in the
+                  # source code but apparently it exists.
+                  source_labels = ["__journal_priority_keyword"];
+                  target_label = "level";
+                }
               ];
-            pipeline_stages = [
-              {
-                match = {
-                  selector = ''{systemd_unit="dendrite.service"} |~ ".*Failed to fetch key for server.*"'';
-                  action = "drop";
-                  drop_counter_reason = "noisy_error";
-                };
-              }
-              {
-                match = {
-                  selector = ''{systemd_unit="dendrite.service"} |~ ".*could not download key for.*"'';
-                  action = "drop";
-                  drop_counter_reason = "noisy_error";
-                };
-              }
-            ];
+            pipeline_stages = cfg.filters;
           }
         ];
       };

Consider giving Nix/NixOS a try! <3