From 8a45686da797e4b3c9748efd5b4879fdffd6b690 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Sat, 20 Sep 2025 21:49:29 +0200 Subject: [PATCH] grafana: Avoid dashboard patching by using victoriametrics's prometheus compatibility --- hosts/srv-monitor/default.nix | 1 + .../{grafana/default.nix => grafana.nix} | 63 ++++++++++--------- .../grafana/patches/node-exporter-full.patch | 11 ---- 3 files changed, 34 insertions(+), 41 deletions(-) rename modules/system/services/{grafana/default.nix => grafana.nix} (68%) delete mode 100644 modules/system/services/grafana/patches/node-exporter-full.patch diff --git a/hosts/srv-monitor/default.nix b/hosts/srv-monitor/default.nix index f09f7ef..3d8f909 100644 --- a/hosts/srv-monitor/default.nix +++ b/hosts/srv-monitor/default.nix @@ -58,6 +58,7 @@ enable = true; domain = "grafana.${tailscaleDomain}"; datasources = { + prometheus.enable = true; victoriametrics.enable = true; victorialogs.enable = true; }; diff --git a/modules/system/services/grafana/default.nix b/modules/system/services/grafana.nix similarity index 68% rename from modules/system/services/grafana/default.nix rename to modules/system/services/grafana.nix index 977653c..aa7364b 100644 --- a/modules/system/services/grafana/default.nix +++ b/modules/system/services/grafana.nix @@ -19,6 +19,13 @@ in default = 3000; }; datasources = { + prometheus = { + enable = lib.mkEnableOption ""; + url = lib.mkOption { + type = lib.types.nonEmptyStr; + default = "https://metrics.${config.custom.services.tailscale.domain}"; + }; + }; victoriametrics = { enable = lib.mkEnableOption ""; url = lib.mkOption { @@ -69,34 +76,36 @@ in dashboards.settings = { # TODO: Uncomment when upgrading to 25.11 # prune = true; - providers = [ - { - name = "Dashboards"; - disableDeletion = true; - options = { - path = "/etc/grafana-dashboards"; - foldersFromFilesStructure = true; - }; - } - ]; + providers = lib.singleton { + name = "Dashboards"; + options.path = "/etc/grafana-dashboards"; + }; }; datasources.settings = { # TODO: Uncomment when upgrading to 25.11 # prune = true; datasources = - (lib.optional cfg.datasources.victoriametrics.enable { + (lib.optional cfg.datasources.prometheus.enable { + name = "Prometheus"; + type = "prometheus"; + inherit (cfg.datasources.prometheus) url; + isDefault = true; + jsonData = { + prometheusType = "Prometheus"; + prometheusVersion = "2.50.0"; + }; + }) + ++ (lib.optional cfg.datasources.victoriametrics.enable { name = "VictoriaMetrics"; type = "victoriametrics-metrics-datasource"; - access = "proxy"; - url = "https://metrics.${config.custom.services.tailscale.domain}"; - isDefault = true; + inherit (cfg.datasources.victoriametrics) url; + isDefault = false; }) ++ (lib.optional cfg.datasources.victorialogs.enable { name = "VictoriaLogs"; type = "victoriametrics-logs-datasource"; - access = "proxy"; - url = "https://logs.${config.custom.services.tailscale.domain}"; + inherit (cfg.datasources.victorialogs) url; isDefault = false; }); }; @@ -108,19 +117,13 @@ in ++ (lib.optional cfg.datasources.victorialogs.enable victoriametrics-logs-datasource); }; - environment.etc."grafana-dashboards/node-exporter-full.json".source = - lib.mkIf cfg.dashboards.node-exporter-full.enable - ( - pkgs.fetchurl { - name = "node-exporter-full.json"; - url = "https://grafana.com/api/dashboards/1860/revisions/41/download"; - hash = "sha256-A6/4QjcMzkry68fSPwNdHq8i6SGwaKwZXVKDZB5h71A="; - downloadToTemp = true; - postFetch = '' - patch $downloadedFile < ${./patches/node-exporter-full.patch} - mv $downloadedFile $out - ''; - } - ); + environment.etc."grafana-dashboards/node-exporter-full.json" = { + enable = cfg.dashboards.node-exporter-full.enable; + source = pkgs.fetchurl { + name = "node-exporter-full.json"; + url = "https://grafana.com/api/dashboards/1860/revisions/41/download"; + hash = "sha256-EywgxEayjwNIGDvSmA/S56Ld49qrTSbIYFpeEXBJlTs="; + }; + }; }; } diff --git a/modules/system/services/grafana/patches/node-exporter-full.patch b/modules/system/services/grafana/patches/node-exporter-full.patch deleted file mode 100644 index 446005b..0000000 --- a/modules/system/services/grafana/patches/node-exporter-full.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- v1.json 2025-06-27 15:13:02.187282992 -0600 -+++ v2.json 2025-06-27 15:12:49.094889325 -0600 -@@ -16015,7 +16015,7 @@ - "label": "Datasource", - "name": "DS_PROMETHEUS", - "options": [], -- "query": "prometheus", -+ "query": "victoriametrics-metrics-datasource", - "refresh": 1, - "regex": "", - "type": "datasource" \ No newline at end of file