From 7e15151bec920c4ba3750bbb7713814d7907d9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 3 Dec 2024 00:29:35 +0100 Subject: [PATCH] Change monitoring --- system/monitoring.nix | 38 ---------------------------------- system/monitoring/default.nix | 7 +++++++ system/monitoring/logs.nix | 39 +++++++++++++++++++++++++++++++++++ system/monitoring/metrics.nix | 11 ++++++++++ 4 files changed, 57 insertions(+), 38 deletions(-) delete mode 100644 system/monitoring.nix create mode 100644 system/monitoring/default.nix create mode 100644 system/monitoring/logs.nix create mode 100644 system/monitoring/metrics.nix diff --git a/system/monitoring.nix b/system/monitoring.nix deleted file mode 100644 index b3da7e0..0000000 --- a/system/monitoring.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ pkgs, ... }: -{ - environment.systemPackages = with pkgs; [ - prometheus-node-exporter - prometheus-systemd-exporter - ]; - - systemd.services."node-exporter" = { - enable = true; - unitConfig = { - Description = "Prometheus Node Exporter"; - After = [ "network.target" ]; - }; - serviceConfig = { - ExecStart = "${pkgs.prometheus-node-exporter}/bin/node_exporter"; - }; - wantedBy = [ "multi-user.target" ]; - }; - - systemd.services."systemd-exporter" = { - enable = true; - unitConfig = { - Description = "Prometheus Systemd Exporter"; - After = [ "network.target" ]; - }; - serviceConfig = { - ExecStart = "${pkgs.prometheus-systemd-exporter}/bin/systemd_exporter"; - }; - wantedBy = [ "multi-user.target" ]; - }; - - networking.firewall.allowedTCPPorts = [ - 5001 - 9100 - 9558 - 8989 - ]; -} diff --git a/system/monitoring/default.nix b/system/monitoring/default.nix new file mode 100644 index 0000000..351331d --- /dev/null +++ b/system/monitoring/default.nix @@ -0,0 +1,7 @@ +{ ... }: +{ + imports = [ + ./metrics.nix + ./logs.nix + ]; +} diff --git a/system/monitoring/logs.nix b/system/monitoring/logs.nix new file mode 100644 index 0000000..e003f97 --- /dev/null +++ b/system/monitoring/logs.nix @@ -0,0 +1,39 @@ +{ ... }: +{ + services.promtail = { + enable = true; + configuration = { + server = { + http_listen_address = "0.0.0.0"; + http_listen_port = 9099; + grpc_listen_address = "0.0.0.0"; + grpc_listen_port = 9098; + }; + + clients = [ + { + url = "http://monitoring01.home.2rjus.net:3100/loki/api/v1/push"; + } + ]; + + scrape_configs = [ + { + job_name = "journal"; + journal = { + json = true; + }; + relabel_configs = [ + { + source_labels = [ "__journal__systemd_unit" ]; + target_label = "systemd_unit"; + } + { + source_labels = [ "__journal__hostname" ]; + target_label = "host"; + } + ]; + } + ]; + }; + }; +} diff --git a/system/monitoring/metrics.nix b/system/monitoring/metrics.nix new file mode 100644 index 0000000..6af75b9 --- /dev/null +++ b/system/monitoring/metrics.nix @@ -0,0 +1,11 @@ +{ ... }: +{ + services.prometheus.exporters.node = { + enable = true; + openFirewall = true; + enabledCollectors = [ + "systemd" + "logind" + ]; + }; +}