about summary refs log tree commit diff
path: root/modules/monitoring
diff options
context:
space:
mode:
Diffstat (limited to 'modules/monitoring')
-rw-r--r--modules/monitoring/default.nix181
1 files changed, 90 insertions, 91 deletions
diff --git a/modules/monitoring/default.nix b/modules/monitoring/default.nix
index 164ac5d..04fcccc 100644
--- a/modules/monitoring/default.nix
+++ b/modules/monitoring/default.nix
@@ -4,16 +4,15 @@
   pkgs,
   ...
 }:
-with lib;
 let
   cfg = config.nixfiles.modules.monitoring;
 in
 {
-  options.nixfiles.modules.monitoring.enable = mkEnableOption ''
+  options.nixfiles.modules.monitoring.enable = lib.mkEnableOption ''
     a glue to provision a monitoring stack
   '';
 
-  config = mkIf cfg.enable {
+  config = lib.mkIf cfg.enable {
     nixfiles.modules = {
       alertmanager.enable = true;
       grafana.enable = true;
@@ -34,27 +33,27 @@ in
 
           # https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources
           datasources.settings.datasources = with config.nixfiles.modules; [
-            (mkIf alertmanager.enable {
+            (lib.mkIf alertmanager.enable {
               name = "Alertmanager";
               type = "alertmanager";
               access = "proxy";
               url = "https://${alertmanager.domain}";
               jsonData.implementation = "prometheus";
             })
-            (mkIf loki.enable {
+            (lib.mkIf loki.enable {
               name = "Loki";
               type = "loki";
               access = "proxy";
               url = "https://${loki.domain}";
               isDefault = true;
             })
-            (mkIf prometheus.enable {
+            (lib.mkIf prometheus.enable {
               name = "Prometheus";
               type = "prometheus";
               access = "proxy";
               url = "https://${prometheus.domain}";
             })
-            (mkIf redis.enable {
+            (lib.mkIf redis.enable {
               name = "Redis";
               type = "redis-datasource";
               access = "proxy";
@@ -63,19 +62,19 @@ in
             })
           ];
           datasources.settings.deleteDatasources = with config.nixfiles.modules; [
-            (mkIf (!alertmanager.enable) {
+            (lib.mkIf (!alertmanager.enable) {
               name = "Alertmanager";
               orgId = 1;
             })
-            (mkIf (!loki.enable) {
+            (lib.mkIf (!loki.enable) {
               name = "Loki";
               orgId = 1;
             })
-            (mkIf (!prometheus.enable) {
+            (lib.mkIf (!prometheus.enable) {
               name = "Prometheus";
               orgId = 1;
             })
-            (mkIf (!redis.enable) {
+            (lib.mkIf (!redis.enable) {
               name = "Redis";
               orgId = 1;
             })
@@ -137,21 +136,18 @@ in
 
       prometheus = {
         scrapeConfigs =
-          with my.configurations;
-          mapAttrsToList
+          lib.mapAttrsToList
             (name: value: {
               job_name = name;
               static_configs = [
                 {
-                  targets =
-                    with value;
-                    map (
-                      host:
-                      concatStringsSep ":" [
-                        (if isAttrs host then host.hostname else host)
-                        (toString port)
-                      ]
-                    ) hosts;
+                  targets = map (
+                    host:
+                    lib.concatStringsSep ":" [
+                      (if lib.isAttrs host then host.hostname else host)
+                      (toString value.port)
+                    ]
+                  ) value.hosts;
                 }
               ];
               relabel_configs = [
@@ -160,76 +156,79 @@ in
                   regex = "([^:]+):\\d+";
                   target_label = "instance";
                 }
-              ] ++ optionals (hasAttr "relabel" value) value.relabel;
+              ] ++ lib.optionals (lib.hasAttr "relabel" value) value.relabel;
             })
-            {
-              promtail = {
-                hosts = [
-                  manwe
-                  tulkas
-                  varda
-                  yavanna
-                ];
-                inherit (config.nixfiles.modules.promtail) port;
-              };
-              ntfy = {
-                hosts = [ manwe ];
-                inherit (config.nixfiles.modules.ntfy.prometheus) port;
-              };
-              soju = {
-                hosts = [ "127.0.0.1" ];
-                inherit (config.nixfiles.modules.soju.prometheus) port;
-              };
-              endlessh-go = {
-                hosts = [
-                  manwe
-                  tulkas
-                  varda
-                  yavanna
-                ];
-                inherit (config.services.endlessh-go.prometheus) port;
-              };
-              exportarr-prowlarr = {
-                hosts = [ yavanna ];
-                inherit (config.services.prometheus.exporters.exportarr-prowlarr) port;
-              };
-              exportarr-lidarr = {
-                hosts = [ yavanna ];
-                inherit (config.services.prometheus.exporters.exportarr-lidarr) port;
-              };
-              nginx = {
-                hosts = [
-                  manwe
-                  yavanna
-                ];
-                inherit (config.services.prometheus.exporters.nginx) port;
-              };
-              node = {
-                hosts = [
-                  manwe
-                  tulkas
-                  varda
-                  yavanna
-                ];
-                inherit (config.services.prometheus.exporters.node) port;
-              };
-              postgres = {
-                hosts = [ manwe ];
-                inherit (config.services.prometheus.exporters.postgres) port;
-              };
-              redis = {
-                hosts = [ manwe ];
-                inherit (config.services.prometheus.exporters.redis) port;
-              };
-              unbound = {
-                hosts = [ manwe ];
-                inherit (config.services.prometheus.exporters.unbound) port;
-              };
-              wireguard = {
-                hosts = [ manwe ];
-                inherit (config.services.prometheus.exporters.wireguard) port;
-              };
-            };
+            (
+              with lib.my.configurations;
+              {
+                promtail = {
+                  hosts = [
+                    manwe
+                    tulkas
+                    varda
+                    yavanna
+                  ];
+                  inherit (config.nixfiles.modules.promtail) port;
+                };
+                ntfy = {
+                  hosts = [ manwe ];
+                  inherit (config.nixfiles.modules.ntfy.prometheus) port;
+                };
+                soju = {
+                  hosts = [ "127.0.0.1" ];
+                  inherit (config.nixfiles.modules.soju.prometheus) port;
+                };
+                endlessh-go = {
+                  hosts = [
+                    manwe
+                    tulkas
+                    varda
+                    yavanna
+                  ];
+                  inherit (config.services.endlessh-go.prometheus) port;
+                };
+                exportarr-prowlarr = {
+                  hosts = [ yavanna ];
+                  inherit (config.services.prometheus.exporters.exportarr-prowlarr) port;
+                };
+                exportarr-lidarr = {
+                  hosts = [ yavanna ];
+                  inherit (config.services.prometheus.exporters.exportarr-lidarr) port;
+                };
+                nginx = {
+                  hosts = [
+                    manwe
+                    yavanna
+                  ];
+                  inherit (config.services.prometheus.exporters.nginx) port;
+                };
+                node = {
+                  hosts = [
+                    manwe
+                    tulkas
+                    varda
+                    yavanna
+                  ];
+                  inherit (config.services.prometheus.exporters.node) port;
+                };
+                postgres = {
+                  hosts = [ manwe ];
+                  inherit (config.services.prometheus.exporters.postgres) port;
+                };
+                redis = {
+                  hosts = [ manwe ];
+                  inherit (config.services.prometheus.exporters.redis) port;
+                };
+                unbound = {
+                  hosts = [ manwe ];
+                  inherit (config.services.prometheus.exporters.unbound) port;
+                };
+                wireguard = {
+                  hosts = [ manwe ];
+                  inherit (config.services.prometheus.exporters.wireguard) port;
+                };
+              }
+            );
 
         ruleFiles = [
           ./rules/nginx.yaml

Consider giving Nix/NixOS a try! <3