grafana: Remove prometheus load balancer and offer all instance as possible datasources

This commit is contained in:
SebastianStork 2026-03-01 14:00:52 +01:00
parent 0e643d568b
commit 4529366841
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q

View file

@ -7,13 +7,6 @@
}: }:
let let
cfg = config.custom.web-services.grafana; cfg = config.custom.web-services.grafana;
prometheusDomains =
allHosts
|> lib.attrValues
|> lib.map (host: host.config.custom.services.prometheus)
|> lib.filter (prometheus: prometheus.enable)
|> lib.map (prometheus: prometheus.domain);
in in
{ {
options.custom.web-services.grafana = { options.custom.web-services.grafana = {
@ -26,15 +19,6 @@ in
type = lib.types.port; type = lib.types.port;
default = 3000; default = 3000;
}; };
datasources.prometheus = {
enable = lib.mkEnableOption "" // {
default = prometheusDomains != [ ];
};
url = lib.mkOption {
type = lib.types.nonEmptyStr;
default = "https://metrics.${config.custom.networking.overlay.fqdn}";
};
};
dashboards.nodeExporter.enable = lib.mkEnableOption "" // { dashboards.nodeExporter.enable = lib.mkEnableOption "" // {
default = true; default = true;
}; };
@ -73,21 +57,24 @@ in
datasources.settings = { datasources.settings = {
prune = true; prune = true;
datasources = lib.optional cfg.datasources.prometheus.enable { datasources =
name = "Prometheus"; allHosts
|> lib.attrValues
|> lib.filter (host: host.config.custom.services.prometheus.enable)
|> lib.map (host: {
name = "Prometheus ${host.config.networking.hostName}";
type = "prometheus"; type = "prometheus";
inherit (cfg.datasources.prometheus) url; url = "https://${host.config.custom.services.prometheus.domain}";
isDefault = true; isDefault = host.config.networking.hostName == config.networking.hostName;
jsonData = { jsonData = {
prometheusType = "Prometheus"; prometheusType = "Prometheus";
prometheusVersion = "3.7.2"; prometheusVersion = "3.7.2";
}; };
});
}; };
}; };
}; };
};
# https://grafana.com/grafana/dashboards/1860-node-exporter-full/ # https://grafana.com/grafana/dashboards/1860-node-exporter-full/
environment.etc."grafana-dashboards/node-exporter-full.json" = { environment.etc."grafana-dashboards/node-exporter-full.json" = {
enable = cfg.dashboards.nodeExporter.enable; enable = cfg.dashboards.nodeExporter.enable;
@ -98,20 +85,6 @@ in
}; };
}; };
custom.services.caddy = { custom.services.caddy.virtualHosts.${cfg.domain}.port = cfg.port;
virtualHosts.${cfg.domain}.port = cfg.port;
virtualHosts."metrics.${config.custom.networking.overlay.fqdn}".extraConfig =
let
upstreams = prometheusDomains |> lib.map (domain: "https://${domain}") |> lib.concatStringsSep " ";
in
''
reverse_proxy ${upstreams} {
header_up Host {upstream_hostport}
lb_policy first
health_uri /api/v1/status/buildinfo
}
'';
};
}; };
} }