diff --git a/base/default.nix b/base/default.nix index 741d79e..8219a23 100644 --- a/base/default.nix +++ b/base/default.nix @@ -25,6 +25,9 @@ ./services/nginx.nix ./services/openssh.nix ./services/postfix.nix + ./services/prometheus-node-exporter.nix + ./services/prometheus-systemd-exporter.nix + ./services/promtail.nix ./services/smartd.nix ./services/thermald.nix ./services/userborn.nix diff --git a/base/services/prometheus-node-exporter.nix b/base/services/prometheus-node-exporter.nix new file mode 100644 index 0000000..bdacdb1 --- /dev/null +++ b/base/services/prometheus-node-exporter.nix @@ -0,0 +1,23 @@ +{ config, lib, values, ... }: +let + cfg = config.services.prometheus.exporters.node; +in +{ + services.prometheus.exporters.node = { + enable = lib.mkDefault true; + port = 9100; + enabledCollectors = [ "systemd" ]; + }; + + systemd.services.prometheus-node-exporter.serviceConfig = lib.mkIf cfg.enable { + IPAddressDeny = "any"; + IPAddressAllow = [ + "127.0.0.1" + "::1" + values.hosts.ildkule.ipv4 + values.hosts.ildkule.ipv6 + ]; + }; + + networking.firewall.allowedTCPPorts = lib.mkIf cfg.enable [ cfg.port ]; +} diff --git a/base/services/prometheus-systemd-exporter.nix b/base/services/prometheus-systemd-exporter.nix new file mode 100644 index 0000000..0599c04 --- /dev/null +++ b/base/services/prometheus-systemd-exporter.nix @@ -0,0 +1,26 @@ +{ config, lib, values, ... }: +let + cfg = config.services.prometheus.exporters.systemd; +in +{ + services.prometheus.exporters.systemd = { + enable = lib.mkDefault true; + port = 9101; + extraFlags = [ + "--systemd.collector.enable-restart-count" + "--systemd.collector.enable-ip-accounting" + ]; + }; + + systemd.services.prometheus-systemd-exporter.serviceConfig = { + IPAddressDeny = "any"; + IPAddressAllow = [ + "127.0.0.1" + "::1" + values.hosts.ildkule.ipv4 + values.hosts.ildkule.ipv6 + ]; + }; + + networking.firewall.allowedTCPPorts = lib.mkIf cfg.enable [ cfg.port ]; +} diff --git a/base/services/promtail.nix b/base/services/promtail.nix new file mode 100644 index 0000000..f8f7b85 --- /dev/null +++ b/base/services/promtail.nix @@ -0,0 +1,38 @@ +{ config, lib, values, ... }: +let + cfg = config.services.prometheus.exporters.node; +in +{ + services.promtail = { + enable = lib.mkDefault true; + configuration = { + server = { + http_listen_port = 28183; + grpc_listen_port = 0; + }; + clients = [{ + url = "http://ildkule.pvv.ntnu.no:3100/loki/api/v1/push"; + }]; + scrape_configs = [{ + job_name = "systemd-journal"; + journal = { + max_age = "12h"; + labels = { + job = "systemd-journal"; + host = config.networking.hostName; + }; + }; + relabel_configs = [ + { + source_labels = [ "__journal__systemd_unit" ]; + target_label = "unit"; + } + { + source_labels = [ "__journal_priority_keyword" ]; + target_label = "level"; + } + ]; + }]; + }; + }; +} diff --git a/hosts/bakke/configuration.nix b/hosts/bakke/configuration.nix index 1aa2b9e..1ecda1d 100644 --- a/hosts/bakke/configuration.nix +++ b/hosts/bakke/configuration.nix @@ -3,7 +3,6 @@ imports = [ ./hardware-configuration.nix ../../base - ../../misc/metrics-exporters.nix ./filesystems.nix ]; diff --git a/hosts/bekkalokk/configuration.nix b/hosts/bekkalokk/configuration.nix index 5795cea..61ae4f0 100644 --- a/hosts/bekkalokk/configuration.nix +++ b/hosts/bekkalokk/configuration.nix @@ -4,7 +4,6 @@ ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) ./services/bluemap.nix ./services/idp-simplesamlphp diff --git a/hosts/bicep/configuration.nix b/hosts/bicep/configuration.nix index e1708a0..1c43fe7 100644 --- a/hosts/bicep/configuration.nix +++ b/hosts/bicep/configuration.nix @@ -4,7 +4,6 @@ ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) ./services/nginx ./services/calendar-bot.nix diff --git a/hosts/brzeczyszczykiewicz/configuration.nix b/hosts/brzeczyszczykiewicz/configuration.nix index b99fb3b..393a2ad 100644 --- a/hosts/brzeczyszczykiewicz/configuration.nix +++ b/hosts/brzeczyszczykiewicz/configuration.nix @@ -4,7 +4,6 @@ # Include the results of the hardware scan. ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) ./services/grzegorz.nix ]; diff --git a/hosts/georg/configuration.nix b/hosts/georg/configuration.nix index f628c45..0a8aa27 100644 --- a/hosts/georg/configuration.nix +++ b/hosts/georg/configuration.nix @@ -4,7 +4,6 @@ # Include the results of the hardware scan. ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) (fp /modules/grzegorz.nix) ]; diff --git a/hosts/ildkule/configuration.nix b/hosts/ildkule/configuration.nix index c6c2f1d..fae804e 100644 --- a/hosts/ildkule/configuration.nix +++ b/hosts/ildkule/configuration.nix @@ -4,7 +4,6 @@ # Include the results of the hardware scan. ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) ./services/monitoring ./services/nginx diff --git a/hosts/kommode/configuration.nix b/hosts/kommode/configuration.nix index 6305162..8a6fac7 100644 --- a/hosts/kommode/configuration.nix +++ b/hosts/kommode/configuration.nix @@ -4,7 +4,6 @@ # Include the results of the hardware scan. ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) ./services/gitea ./services/nginx.nix @@ -31,4 +30,3 @@ system.stateVersion = "24.11"; } - diff --git a/hosts/lupine/configuration.nix b/hosts/lupine/configuration.nix index 54f2910..834bbdf 100644 --- a/hosts/lupine/configuration.nix +++ b/hosts/lupine/configuration.nix @@ -4,7 +4,6 @@ ./hardware-configuration/${lupineName}.nix (fp /base) - (fp /misc/metrics-exporters.nix) ./services/gitea-runner.nix ]; diff --git a/hosts/shark/configuration.nix b/hosts/shark/configuration.nix index 65c036d..d0f932f 100644 --- a/hosts/shark/configuration.nix +++ b/hosts/shark/configuration.nix @@ -4,7 +4,6 @@ # Include the results of the hardware scan. ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) ]; sops.defaultSopsFile = fp /secrets/shark/shark.yaml; diff --git a/hosts/ustetind/configuration.nix b/hosts/ustetind/configuration.nix index 3c3f0c9..dadcf93 100644 --- a/hosts/ustetind/configuration.nix +++ b/hosts/ustetind/configuration.nix @@ -3,7 +3,6 @@ { imports = [ (fp /base) - (fp /misc/metrics-exporters.nix) ./services/gitea-runners.nix ]; diff --git a/hosts/wenche/configuration.nix b/hosts/wenche/configuration.nix index 1639b63..c3f0c6f 100644 --- a/hosts/wenche/configuration.nix +++ b/hosts/wenche/configuration.nix @@ -4,7 +4,6 @@ # Include the results of the hardware scan. ./hardware-configuration.nix (fp /base) - (fp /misc/metrics-exporters.nix) ]; nix.settings.trusted-users = [ "@nix-builder-users" ]; diff --git a/misc/metrics-exporters.nix b/misc/metrics-exporters.nix deleted file mode 100644 index 8dfb738..0000000 --- a/misc/metrics-exporters.nix +++ /dev/null @@ -1,80 +0,0 @@ -{ config, pkgs, values, ... }: - -{ - services.prometheus.exporters.node = { - enable = true; - port = 9100; - enabledCollectors = [ "systemd" ]; - }; - - systemd.services.prometheus-node-exporter.serviceConfig = { - IPAddressDeny = "any"; - IPAddressAllow = [ - "127.0.0.1" - "::1" - values.hosts.ildkule.ipv4 - values.hosts.ildkule.ipv6 - ]; - }; - - - services.prometheus.exporters.systemd = { - enable = true; - port = 9101; - extraFlags = [ - "--systemd.collector.enable-restart-count" - "--systemd.collector.enable-ip-accounting" - ]; - }; - - systemd.services.prometheus-systemd-exporter.serviceConfig = { - IPAddressDeny = "any"; - IPAddressAllow = [ - "127.0.0.1" - "::1" - values.hosts.ildkule.ipv4 - values.hosts.ildkule.ipv6 - ]; - }; - - - networking.firewall.allowedTCPPorts = [ 9100 9101 ]; - - services.promtail = { - enable = true; - configuration = { - server = { - http_listen_port = 28183; - grpc_listen_port = 0; - }; - clients = [ - { - url = "http://ildkule.pvv.ntnu.no:3100/loki/api/v1/push"; - } - ]; - scrape_configs = [ - { - job_name = "systemd-journal"; - journal = { - max_age = "12h"; - labels = { - job = "systemd-journal"; - host = config.networking.hostName; - }; - }; - relabel_configs = [ - { - source_labels = [ "__journal__systemd_unit" ]; - target_label = "unit"; - } - { - source_labels = [ "__journal_priority_keyword" ]; - target_label = "level"; - } - ]; - } - ]; - }; - }; - -}