Big changes to prometheus scrapers

This commit is contained in:
niten 2024-07-27 18:16:07 -07:00
parent b0b3f03231
commit 730c93fc4c

View File

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }@toplevel:
with lib; with lib;
let cfg = config.fudo.metrics.prometheus; let cfg = config.fudo.metrics.prometheus;
@ -15,35 +15,46 @@ in {
description = "The prometheus package that should be used."; description = "The prometheus package that should be used.";
}; };
service-discovery-dns = mkOption { scrapers = let
type = attrsOf (listOf str); scraperOpts.options = {
description = '' name = mkOption {
A map of exporter type to a list of domains to use for service discovery. type = str;
''; description = "Name of this exporter.";
example = { };
node = [ "node._metrics._tcp.my-domain.com" ];
postfix = [ "postfix._metrics._tcp.my-domain.com" ];
};
default = {
dovecot = [ ];
node = [ ];
postfix = [ ];
rspamd = [ ];
};
};
static-targets = mkOption { secured = mkOption {
type = attrsOf (listOf str); type = str;
description = '' description = "Whether to use https instead of http.";
A map of exporter type to a list of host:ports from which to collect metrics. default = !toplevel.config.fudo.metrics.prometheus.private-network;
''; };
example = { node = [ "my-host.my-domain:1111" ]; };
default = { path = mkOption {
dovecot = [ ]; type = str;
node = [ ]; description = "Host path at which to find exported metrics.";
postfix = [ ]; default = "/metrics";
rspamd = [ ]; };
port = mkOption {
type = port;
description = "Port on which to scrape for metrics.";
default = 80;
};
hostnames = mkOption {
type = listOf str;
description = "Explicit list of hosts to scrape for metrics.";
default = [ ];
};
dns-sd-records = mkOption {
type = listOf str;
description = "List of DNS records to query for hosts to scrape.";
default = [ ];
};
}; };
in mkOption {
type = listOf (submodule scraperOpts);
default = [ ];
}; };
docker-hosts = mkOption { docker-hosts = mkOption {
@ -133,21 +144,17 @@ in {
port = 9090; port = 9090;
scrapeConfigs = let scrapeConfigs = let
make-job = type: { mkScraper = { name, secured, path, port, hostnames, dns-sd-records }: {
job_name = type; job_name = name;
honor_labels = false; honor_labels = false;
scheme = if cfg.private-network then "http" else "https"; scheme = if secured then "https" else "http";
metrics_path = "/metrics/${type}"; metrics_path = path;
static_configs = if (hasAttr type cfg.static-targets) then [{ static_configs =
targets = cfg.static-targets.${type}; let attachPort = hostname: "${hostname}:${toString port}";
}] else in [{ targets = map attachPort hostnames; }];
[ ]; dns_sd_configs = [{ names = dns-sd-records; }];
dns_sd_configs = if (hasAttr type cfg.service-discovery-dns) then [{
names = cfg.service-discovery-dns.${type};
}] else
[ ];
}; };
in map make-job [ "docker" "node" "dovecot" "postfix" "rspamd" ]; in map mkScraper cfg.scrapers;
pushgateway = { pushgateway = {
enable = if (cfg.push-url != null) then true else false; enable = if (cfg.push-url != null) then true else false;