about summary refs log tree commit diff
path: root/modules/services/metrics-exporter
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2023-04-23 11:40:28 -0700
committerFranck Cuny <franck@fcuny.net>2023-04-23 14:24:58 -0700
commitd0db12cfc8567818f0a52ef2a7524003d01b051d (patch)
tree4173a48463f5cfd0330872c88b75ffad71b3c322 /modules/services/metrics-exporter
parentnginx: remove the grafana dashboard provider (diff)
downloadworld-d0db12cfc8567818f0a52ef2a7524003d01b051d.tar.gz
modules/services: add loki and promtail
Diffstat (limited to '')
-rw-r--r--modules/services/metrics-exporter/default.nix2
-rw-r--r--modules/services/metrics-exporter/promtail.nix65
2 files changed, 67 insertions, 0 deletions
diff --git a/modules/services/metrics-exporter/default.nix b/modules/services/metrics-exporter/default.nix
index f489f78..c3c471c 100644
--- a/modules/services/metrics-exporter/default.nix
+++ b/modules/services/metrics-exporter/default.nix
@@ -2,6 +2,8 @@
 let cfg = config.my.services.metrics-exporter;
 in
 {
+  imports = [ ./promtail.nix ];
+
   options.my.services.metrics-exporter = with lib; {
     enable = mkEnableOption "Prometheus metrics exporter";
   };
diff --git a/modules/services/metrics-exporter/promtail.nix b/modules/services/metrics-exporter/promtail.nix
new file mode 100644
index 0000000..eb574d0
--- /dev/null
+++ b/modules/services/metrics-exporter/promtail.nix
@@ -0,0 +1,65 @@
+{ config, lib, pkgs, ... }:
+let
+  cfg = config.my.services.metrics-exporter.promtail;
+in
+{
+  options.my.services.metrics-exporter.promtail = with lib; {
+    enable = mkEnableOption "promtail logs exporter";
+  };
+
+  config = lib.mkIf cfg.enable {
+    services.promtail = {
+      enable = true;
+      configuration = {
+        clients = [{ url = "http://192.168.6.40:3100/loki/api/v1/push"; }];
+        scrape_configs = [
+          {
+            job_name = "journal";
+            journal = {
+              json = true;
+              path = "/var/log/journal";
+              max_age = "12h";
+              labels = {
+                host = "carmel";
+                job = "journal";
+                "__path__" = "/var/log/journal";
+              };
+            };
+
+            relabel_configs = [
+              {
+                source_labels = [ "__journal__systemd_unit" ];
+                target_label = "unit";
+              }
+              {
+                source_labels = [ "__journal_priority" ];
+                target_label = "priority";
+              }
+              {
+                source_labels = [ "__journal_syslog_identifier" ];
+                target_label = "syslog_id";
+              }
+            ];
+          }
+
+          {
+            job_name = "nginx";
+            static_configs = [{
+              labels = {
+                host = "carmel";
+                job = "nginx";
+                __path__ = "/var/log/nginx/*";
+              };
+            }];
+          }
+        ];
+
+        server = {
+          http_listen_port = 9832;
+          http_path_prefix = "/promtail";
+          grpc_listen_port = 0;
+        };
+      };
+    };
+  };
+}