From a8b084628f20c231dd941ed8b0feebce6b946b4b Mon Sep 17 00:00:00 2001
From: clerie <git@clerie.de>
Date: Fri, 7 Mar 2025 22:03:34 +0100
Subject: [PATCH] hosts/monitoring-3: Monitor uberspace hosts

---
 hosts/monitoring-3/prometheus.nix | 44 +++++++++++++++++++++++++++++++
 hosts/monitoring-3/secrets.json   |  7 ++---
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/hosts/monitoring-3/prometheus.nix b/hosts/monitoring-3/prometheus.nix
index 17966eb..73abc9f 100644
--- a/hosts/monitoring-3/prometheus.nix
+++ b/hosts/monitoring-3/prometheus.nix
@@ -55,6 +55,11 @@ let
   eachWithEachOther = (f: x: y: lib.lists.flatten (lib.lists.forEach x (a: lib.lists.forEach y (b: f a b))));
 
 in {
+  sops.secrets.uberspace-monitor-password = {
+    owner = "prometheus";
+    group = "prometheus";
+  };
+
   networking.hosts = {
     "::1" = [ "monitoring-3.mon.clerie.de" ]; # fd00:327:327:327::1
   }
@@ -126,6 +131,45 @@ in {
           relabelAddressToInstance
         ];
       }
+      {
+        job_name = "node-exporter-uberspace";
+        scrape_interval = "20s";
+        metrics_path = "/.node-exporter/metrics";
+        basic_auth = {
+          username = "monitor";
+          password_file = config.sops.secrets.uberspace-monitor-password.path;
+        };
+        static_configs = [
+          {
+            targets = [
+              "clerie.uber.space;infra"
+              "cleriewi.uber.space;infra"
+            ];
+          }
+        ];
+        relabel_configs = [
+          {
+            source_labels = [ "__address__" ];
+            regex = "(.+);(.+)";
+            target_label = "service_level";
+            replacement = "\${2}";
+          }
+          {
+            source_labels = [ "__address__" ];
+            regex = "(.+);(.+)";
+            target_label = "__address__";
+            replacement = "\${1}";
+          }
+          {
+            source_labels = [ "__address__" ];
+            target_label = "instance";
+          }
+          {
+            target_label = "job";
+            replacement = "node-exporter";
+          }
+        ];
+      }
       {
         job_name = "nixos-exporter";
         scrape_interval = "1m";
diff --git a/hosts/monitoring-3/secrets.json b/hosts/monitoring-3/secrets.json
index 3a88242..db37e00 100644
--- a/hosts/monitoring-3/secrets.json
+++ b/hosts/monitoring-3/secrets.json
@@ -1,4 +1,5 @@
 {
+	"uberspace-monitor-password": "ENC[AES256_GCM,data:NfM9jxZAMkSGFlPYxreP7LJkr9gA2llyVw96okIKNUQ=,iv:z/LW643T36HpKo/xhHcVnF0EqhEXdoiEkDMH6NQzN9A=,tag:KXR2+kizv3To0EvZ66ak9w==,type:str]",
 	"wg-monitoring": "ENC[AES256_GCM,data:kYFhMbqL7b0rwE2XIaR4QVT8ahoODmpXKzK5gvkODFJVklubwCmq2bLJk94=,iv:eR+VjxdtS4et9I4okzHyA+if1Rxj2/MuiC0CrWXd0Bg=,tag:rMaYMTvO6gWw6WegehDBFQ==,type:str]",
 	"xmpp-password": "ENC[AES256_GCM,data:eBZsBYqo+juLrYZjBqTcKFirHViRsul+wt6kkOmMhCp4xU7Ou8eJAPCOuhvHcUGxRE44L0yIyUObhRgAj0T5QA==,iv:DsLJ3qCZyrdolJBZFT9FJUNQ75pc8Vz32K2a8RJHuLc=,tag:wOxs2Ulw1aSMadWfjGSKsw==,type:str]",
 	"sops": {
@@ -12,8 +13,8 @@
 				"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBxOGNMcm9vRWxMZjBwcmVS\nVGVoS2kwSmZjOHdGMXQwUmlzV3hhbGhhOVhzCkljQi94aUtORldKOFdqeVNXYnJQ\ndS9Vc0hRRisyL1dESk1NOTQ1dVJyMDgKLS0tIE54VlU1cVRXWXRlVGU5RzR5dXkv\nSEZJeElpWDdJYW9WNWxGLzdjdGR1YUUKGZwFPOc4MD97FBRtj1Py4A9Tz/HlzHcK\nX6nYgkYSUycM4g4d3+N+1NKutfWJ7KheuTlhNRDftyLYmmo5wyEtrw==\n-----END AGE ENCRYPTED FILE-----\n"
 			}
 		],
-		"lastmodified": "2024-04-21T17:08:58Z",
-		"mac": "ENC[AES256_GCM,data:UucT7OiO9S3FcO9b1UKPQYXi7v3Ak7/J/VkDN4P9fssS4nky6PyX4oV5UvGcuR3p0pxLAHGJ4rOXj5QbnOqwDqmHfCnoqdItAlXRT1YPdSrelQ/gHyOfexsuV1XLOUS/OXJoYEi3ymKtza4rMIZow+du0YkRxrJQjwM0y8XSa3I=,iv:mDBaVhbHCLdxx5DC7urPPDdVPsCPYqKgLRwfqjLFdnU=,tag:Wpq6ihxIr/eceG12gpOJwQ==,type:str]",
+		"lastmodified": "2025-03-07T20:23:25Z",
+		"mac": "ENC[AES256_GCM,data:6GY06rVSKtQqaV5kLgTU4Wlu+e+dkNhxaPkJqKE8hrfJzO85WU6/iLvuv4ai0u+cUeWcOZatskzUeaVL/NjrRZnsNnxUqWbljLs8//0uUln71D/DWE4Vpb6Uz9I2iHG2Gftv3iyYF3nucrHiSTvyLzb9fDL+eGv0CHa/KmYk97g=,iv:f6xqDtHoBy7h7KRr2J0kYcaf6indqnRrJsYdcv9EHJs=,tag:uliCg2x92qY9SN9hg08Iuw==,type:str]",
 		"pgp": [
 			{
 				"created_at": "2024-04-21T17:08:30Z",
@@ -22,6 +23,6 @@
 			}
 		],
 		"unencrypted_suffix": "_unencrypted",
-		"version": "3.8.1"
+		"version": "3.9.4"
 	}
 }
\ No newline at end of file