From ade130b91fb2361b7a1b0fa72f8526d974bf0e91 Mon Sep 17 00:00:00 2001
From: Florian Sesser <florian@privatestorage.io>
Date: Mon, 31 May 2021 22:27:31 +0000
Subject: [PATCH] Add prometheus scraping config for issuer metrics

---
 morph/grid/local/grid.nix                      |  2 ++
 morph/lib/make-monitoring.nix                  |  2 ++
 nixos/modules/monitoring/server/prometheus.nix | 14 ++++++++++++++
 3 files changed, 18 insertions(+)

diff --git a/morph/grid/local/grid.nix b/morph/grid/local/grid.nix
index b71c6e61..069545e3 100644
--- a/morph/grid/local/grid.nix
+++ b/morph/grid/local/grid.nix
@@ -17,6 +17,7 @@ import ../../lib/make-grid.nix {
     };
     vpnClientIPs = [ "172.23.23.11" "172.23.23.12" "172.23.23.13" ];
     nodeExporterTargets = [ "monitoring1" "payments1" "storage1" "storage2" ];
+    issuerTargets = [ "payments1" ];
 
   in {
     "payments1" = import ../../lib/make-issuer.nix (rec {
@@ -49,6 +50,7 @@ import ../../lib/make-grid.nix {
       inherit vpnClientIPs;
       inherit hostsMap;
       inherit nodeExporterTargets;
+      inherit issuerTargets;
       hardware = import ./virtual-hardware.nix ({ inherit publicIPv4; });
       stateVersion = "19.09";
       inherit sshUsers;
diff --git a/morph/lib/make-monitoring.nix b/morph/lib/make-monitoring.nix
index acd8c1e9..815b9fe7 100644
--- a/morph/lib/make-monitoring.nix
+++ b/morph/lib/make-monitoring.nix
@@ -10,6 +10,7 @@
 , vpnClientIPs ? null
 , nodeExporterTargets ? []
 , nginxExporterTargets ? []
+, issuerTargets ? []
 , hostsMap ? {}
 , ... }: let
 
@@ -69,6 +70,7 @@ in rec {
   services.private-storage.monitoring.prometheus = {
     inherit nodeExporterTargets;
     inherit nginxExporterTargets;
+    inherit issuerTargets;
   };
 
   system.stateVersion = stateVersion;
diff --git a/nixos/modules/monitoring/server/prometheus.nix b/nixos/modules/monitoring/server/prometheus.nix
index 36c2ba64..72b57a21 100644
--- a/nixos/modules/monitoring/server/prometheus.nix
+++ b/nixos/modules/monitoring/server/prometheus.nix
@@ -26,6 +26,11 @@ in {
       example = lib.literalExample "[ node1 node2 ]";
       description = "List of nodes (hostnames or IPs) to scrape.";
     };
+    issuerTargets = lib.mkOption {
+      type = with lib.types; listOf str;
+      example = lib.literalExample "[ node1 node2 ]";
+      description = "List of nodes (hostnames or IPs) to scrape.";
+    };
   };
 
   config = rec {
@@ -49,6 +54,15 @@ in {
           }];
           relabel_configs = [ dropPortNumber ];
         }
+        {
+          job_name = "issuers";
+          scheme = "https";
+          tls_config.insecure_skip_verify = true;
+          static_configs = [{
+            targets = cfg.issuerTargets;
+          }];
+          relabel_configs = [ dropPortNumber ];
+        }
       ];
     };
   };
-- 
GitLab