Better default for scraper port

This commit is contained in:
niten 2024-07-27 18:29:00 -07:00
parent 730c93fc4c
commit 37ea31b085

View File

@ -37,10 +37,14 @@ in {
port = mkOption { port = mkOption {
type = port; type = port;
description = "Port on which to scrape for metrics."; description = "Port on which to scrape for metrics.";
default = 80; default =
if toplevel.config.fudo.metrics.prometheus.private-network then
80
else
443;
}; };
hostnames = mkOption { static-targets = mkOption {
type = listOf str; type = listOf str;
description = "Explicit list of hosts to scrape for metrics."; description = "Explicit list of hosts to scrape for metrics.";
default = [ ]; default = [ ];
@ -144,14 +148,15 @@ in {
port = 9090; port = 9090;
scrapeConfigs = let scrapeConfigs = let
mkScraper = { name, secured, path, port, hostnames, dns-sd-records }: { mkScraper =
{ name, secured, path, port, static-targets, dns-sd-records }: {
job_name = name; job_name = name;
honor_labels = false; honor_labels = false;
scheme = if secured then "https" else "http"; scheme = if secured then "https" else "http";
metrics_path = path; metrics_path = path;
static_configs = static_configs =
let attachPort = hostname: "${hostname}:${toString port}"; let attachPort = target: "${target}:${toString port}";
in [{ targets = map attachPort hostnames; }]; in [{ targets = map attachPort static-targets; }];
dns_sd_configs = [{ names = dns-sd-records; }]; dns_sd_configs = [{ names = dns-sd-records; }];
}; };
in map mkScraper cfg.scrapers; in map mkScraper cfg.scrapers;