summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/monitoring/module.nix50
-rw-r--r--modules/monitoring/postgres.nix12
-rw-r--r--modules/monitoring/synapse.nix82
-rw-r--r--modules/monitoring/system.nix14
4 files changed, 59 insertions, 99 deletions
diff --git a/modules/monitoring/module.nix b/modules/monitoring/module.nix
index 30c313b..62ff1ea 100644
--- a/modules/monitoring/module.nix
+++ b/modules/monitoring/module.nix
@@ -13,7 +13,7 @@ in
   imports = [
     # crutches due to nix limitations:
     ./crutches/synapse.nix
-    
+
     # modules
     ./system.nix
     ./postgres.nix
@@ -28,15 +28,10 @@ in
 
     nginxHost = mkStringOption "The virtual host name";
     nginxSsl = lib.mkEnableOption "Enable SSL for Nginx";
-    prometheusScrapeIntervals = lib.mkOption {
-      type = lib.types.listOf lib.types.int;
-      default = [
-        1
-        #2 # kinda pointless?
-        #5 # doesnt help with reliability
-        #15 # might aswell just use a 15s interval on grafana
-      ];
-      description = "Scrape intervals for Prometheus";
+    prometheusScrapeInterval = lib.mkOption {
+      type = lib.types.int;
+      default = 1;
+      description = "Scrape interval for Prometheus";
     };
   };
 
@@ -45,9 +40,7 @@ in
       prometheus = lib.mkIf (cfg.localPrometheus) {
         enable = true;
         listenAddress = "127.0.0.1";
-        extraFlags = [
-          "--storage.tsdb.wal-compression"
-        ];
+        extraFlags = [ "--storage.tsdb.wal-compression" ];
       };
       grafana = lib.mkIf (cfg.localGrafana) {
         enable = true;
@@ -62,24 +55,21 @@ in
         provision = {
           datasources.settings = {
             apiVersion = 1;
-            #            datasources = [
-            #              {
-            #                name = "Prometheus";
-            #                type = "prometheus";
-            #                access = "proxy";
-            #                url = "http://127.0.0.1:${toString config.services.prometheus.port}";
-            #                isDefault = true;
-            #              }
-            #            ];
 
-            datasources = lib.map (interval: {
-              name = "Prometheus-${toString interval}";
-              type = "prometheus";
-              access = "proxy";
-              url = "http://127.0.0.1:${toString config.services.prometheus.port}";
-              #isDefault = true;
-              jsonData.timeInterval = "${toString interval}s";
-            }) cfg.prometheusScrapeIntervals;
+            datasources =
+              lib.map
+                (interval: {
+                  name = "Prometheus-${toString interval}";
+                  type = "prometheus";
+                  access = "proxy";
+                  url = "http://127.0.0.1:${toString config.services.prometheus.port}";
+                  #isDefault = true;
+                  jsonData.timeInterval = "${toString interval}s";
+                })
+                [
+                  1
+                  15
+                ];
           };
         };
       };
diff --git a/modules/monitoring/postgres.nix b/modules/monitoring/postgres.nix
index 5505892..25266fa 100644
--- a/modules/monitoring/postgres.nix
+++ b/modules/monitoring/postgres.nix
@@ -19,13 +19,13 @@ in
       ];
     };
 
-    services.prometheus.scrapeConfigs = (
-      lib.map (interval: {
-        job_name = "postgres-${toString interval}s";
-        scrape_interval = "${toString interval}s";
+    services.prometheus.scrapeConfigs = [
+      {
+        job_name = "postgres";
+        scrape_interval = "${toString cfg.prometheusScrapeInterval}s";
         static_configs = [ { targets = [ "localhost:${toString config.services.prometheus.exporters.postgres.port}" ]; } ];
-      }) cfg.prometheusScrapeIntervals
-    );
+      }
+    ];
 
     services.grafana.provision.dashboards.settings = {
       apiVersion = 1;
diff --git a/modules/monitoring/synapse.nix b/modules/monitoring/synapse.nix
index a279a3d..385e996 100644
--- a/modules/monitoring/synapse.nix
+++ b/modules/monitoring/synapse.nix
@@ -14,39 +14,6 @@ in
       }
     ];
 
-    #services.matrix-synapse.workers = (
-    #  let
-    #    workerNames = config.services.matrix-synapse.workers;
-
-    #    hasMetricsListener =
-    #      (workerName:
-    #      lib.any (
-    #        listener: listener.type == "http" && (lib.any (resourceName: resourceName == "metrics") listener.resources)
-    #      ) config.services.matrix-synapse.workers.${workerName}.worker_listeners);
-
-    #    workerNamesWithoutMetrics = lib.traceVal lib.filter (workerName: (!hasMetricsListener workerName)) workerNames;
-    #  in
-    #  lib.listToAttrs (
-    #    lib.imap (index: workerName: {
-    #      name = workerName;
-    #      value = {
-    #        worker_listeners = [
-    #          {
-    #            type = "http";
-    #            port = 9200 + index;
-    #            resources = [
-    #              {
-    #                names = [ "metrics" ];
-    #                compress = false;
-    #              }
-    #            ];
-    #          }
-    #        ];
-    #      };
-    #    }) workerNamesWithoutMetrics
-    #  )
-    #);
-
     services.matrix-synapse.workers = (
       lib.listToAttrs (
         lib.imap (index: workerName: {
@@ -64,30 +31,33 @@ in
       )
     );
 
-    services.prometheus.scrapeConfigs = (
-      (lib.map (interval: {
-        job_name = "synapse-main-${toString interval}s";
-        scrape_interval = "${toString interval}s";
-        static_configs = [ { targets = [ "localhost:9200" ]; } ];
-        metrics_path = "_synapse/metrics";
-      }) cfg.prometheusScrapeIntervals)
+    services.prometheus.scrapeConfigs =
+      [
+        {
+          job_name = "synapse-main";
+          scrape_interval = "${toString cfg.prometheusScrapeInterval}s";
+          static_configs = [
+            {
+              targets = [ "localhost:9200" ];
+              labels.instance = "synapse";
+            }
+          ];
+          metrics_path = "_synapse/metrics";
+        }
+      ]
       ++ lib.flatten (
-        lib.imap (
-          index: workerName:
-          lib.map (interval: {
-            job_name = "synapse-${workerName}-${toString interval}s";
-            scrape_interval = "${toString interval}s";
-            static_configs = [ 
-            { 
-            targets = [ "localhost:${toString (9200 + index + 1)}" ];
-            
-             } 
-            ];
-            metrics_path = "_synapse/metrics";
-          }) cfg.prometheusScrapeIntervals
-        ) config.monitoring.synapse.workerNames
-      )
-    );
+        lib.imap (index: workerName: {
+          job_name = "synapse-${workerName}s";
+          scrape_interval = "${toString cfg.prometheusScrapeInterval}s";
+          static_configs = [
+            {
+              targets = [ "localhost:${toString (9200 + index + 1)}" ];
+              labels.instance = "synapse";
+            }
+          ];
+          metrics_path = "_synapse/metrics";
+        }) config.monitoring.synapse.workerNames
+      );
 
     services.grafana.provision.dashboards.settings = {
       apiVersion = 1;
diff --git a/modules/monitoring/system.nix b/modules/monitoring/system.nix
index cc1ec66..171a7af 100644
--- a/modules/monitoring/system.nix
+++ b/modules/monitoring/system.nix
@@ -46,13 +46,13 @@ in
       ];
     };
 
-    services.prometheus.scrapeConfigs = (
-        lib.map (interval: {
-            job_name = "node-${toString interval}s";
-            scrape_interval = "${toString interval}s";
-            static_configs = [ { targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; } ];
-        }) cfg.prometheusScrapeIntervals
-    );
+    services.prometheus.scrapeConfigs = [
+      {
+        job_name = "node";
+        scrape_interval = "${toString cfg.prometheusScrapeInterval}s";
+        static_configs = [ { targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; } ];
+      }
+    ];
 
     services.grafana.provision.dashboards.settings = {
       apiVersion = 1;