From 47541c5f2b943df31ad216f2899067b961191fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sun, 2 Jul 2023 05:16:27 +0200 Subject: [PATCH] stats: reduce mkMerge usage --- modules/stats.nix | 119 ++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 63 deletions(-) diff --git a/modules/stats.nix b/modules/stats.nix index 234c2abb..3c5c98cf 100644 --- a/modules/stats.nix +++ b/modules/stats.nix @@ -7,6 +7,7 @@ let !config.boot.isContainer && !(config ? microvm); + nginxStatusPort = 9100; in { options.c3d2.hq.statistics = { @@ -16,50 +17,48 @@ in config = { networking.firewall.allowedTCPPorts = [ 9100 ]; - services = lib.mkMerge [ - (let - nginxStatusPort = 9100; - in { - collectd = lib.mkIf cfg.enable { - enable = true; - extraConfig = '' - FQDNLookup false - Interval 10 + services = { + collectd = lib.mkIf cfg.enable { + enable = true; + extraConfig = '' + FQDNLookup false + Interval 10 + ''; + buildMinimalPackage = true; + plugins = { + logfile = '' + LogLevel info + File STDOUT + ''; + network = '' + Server "grafana.serv.zentralwerk.org" "25826" + ''; + memory = ""; + processes = ""; + disk = ""; + df = ""; + cpu = ""; + entropy = ""; + load = ""; + swap = ""; + cgroups = ""; + vmem = ""; + interface = ""; + } // lib.optionalAttrs isMetal { + sensors = ""; + cpufreq = ""; + irq = ""; + ipmi = ""; + thermal = ""; + } // lib.optionalAttrs config.services.nginx.enable { + nginx = '' + URL "http://localhost:${toString nginxStatusPort}/nginx_status" ''; - buildMinimalPackage = true; - plugins = { - logfile = '' - LogLevel info - File STDOUT - ''; - network = '' - Server "grafana.serv.zentralwerk.org" "25826" - ''; - memory = ""; - processes = ""; - disk = ""; - df = ""; - cpu = ""; - entropy = ""; - load = ""; - swap = ""; - cgroups = ""; - vmem = ""; - interface = ""; - } // lib.optionalAttrs isMetal { - sensors = ""; - cpufreq = ""; - irq = ""; - ipmi = ""; - thermal = ""; - } // lib.optionalAttrs config.services.nginx.enable { - nginx = '' - URL "http://localhost:${toString nginxStatusPort}/nginx_status" - ''; - }; }; + }; - nginx = lib.mkIf config.services.nginx.enable { + nginx = lib.mkMerge [ + (lib.mkIf config.services.nginx.enable { virtualHosts.localhost = { listen = [ { addr = "127.0.0.1"; port = nginxStatusPort; } @@ -74,36 +73,30 @@ in deny all; ''; }; - }; - }) + }) - (lib.mkIf (pkgs.system != "riscv64-linux") { - nginx = { + (lib.mkIf (pkgs.system != "riscv64-linux") { enable = true; virtualHosts."_" = { - listen = - let - port = 9100; - in - [ - { addr = "0.0.0.0"; inherit port; } - { addr = "[::]"; inherit port; } - ]; + listen = let port = 9100; in [ + { addr = "0.0.0.0"; inherit port; } + { addr = "[::]"; inherit port; } + ]; locations."/metrics" = { proxyPass = "http://127.0.0.1:${toString config.services.prometheus.exporters.node.port}/metrics"; extraConfig = libC.hqNetworkOnly; }; }; - }; + }) + ]; - prometheus.exporters.node = { - enable = true; - enabledCollectors = [ "ethtool" "systemd" ]; - listenAddress = "127.0.0.1"; - openFirewall = true; - port = 9101; - }; - }) - ]; + prometheus.exporters.node = lib.mkIf (pkgs.system != "riscv64-linux") { + enable = true; + enabledCollectors = [ "ethtool" "systemd" ]; + listenAddress = "127.0.0.1"; + openFirewall = true; + port = 9101; + }; + }; }; }