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,16 +148,17 @@ in {
port = 9090; port = 9090;
scrapeConfigs = let scrapeConfigs = let
mkScraper = { name, secured, path, port, hostnames, dns-sd-records }: { mkScraper =
job_name = name; { name, secured, path, port, static-targets, dns-sd-records }: {
honor_labels = false; job_name = name;
scheme = if secured then "https" else "http"; honor_labels = false;
metrics_path = path; scheme = if secured then "https" else "http";
static_configs = metrics_path = path;
let attachPort = hostname: "${hostname}:${toString port}"; static_configs =
in [{ targets = map attachPort hostnames; }]; let attachPort = target: "${target}:${toString port}";
dns_sd_configs = [{ names = dns-sd-records; }]; in [{ targets = map attachPort static-targets; }];
}; dns_sd_configs = [{ names = dns-sd-records; }];
};
in map mkScraper cfg.scrapers; in map mkScraper cfg.scrapers;
pushgateway = { pushgateway = {