Skip to content

Various blackbox exporter improvements #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions modules/prometheus.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ in
dnsProbe = lib.mkOption {
type = with lib.types; attrsOf (submodule {
options = {
names = lib.mkOption {
domains = lib.mkOption {
type = with lib.types; listOf str;
example = [ "example.com" ];
description = "Query name to query";
Expand Down Expand Up @@ -109,17 +109,17 @@ in
exporters.blackbox = {
config.modules = lib.mkMerge (
(lib.mapAttrsToList (probeName: opts:
(lib.foldl (x: name: x // {
"dns_${probeName}_${name}" = {
(lib.foldl (x: domain: x // {
"dns_${probeName}_${domain}" = {
dns = {
query_name = name;
query_name = domain;
query_type = opts.type;
valid_rcodes = [ "NOERROR" ];
};
prober = "dns";
timeout = "5s";
};
}) { } opts.names)
}) { } opts.domains)
) cfgb.dnsProbe)

++ lib.mapAttrsToList (name: opts: let
Expand Down Expand Up @@ -162,34 +162,42 @@ in
metrics_path = "/probe";
relabel_configs = [ {
source_labels = [ "__address__" ];
target_label = "__param_target";
target_label = "__param_target"; # __param_* will be rewritten as query string
} {
source_labels = [ "__param_target" ];
target_label = "instance";
} {
# needed because blackbox exporter (ab)uses targets for its targets but we actually need to ask the exporter about the target state
target_label = "__address__";
replacement = cfgb.blackboxExporterURL;
} ];
};

genHttpProbeScrapeConfig = { name, opts }: commonProbeScrapeConfig // {
job_name = "blackbox_http_${name}";
params.module = [ "http_${name}" ];
inherit (commonProbeScrapeConfig) relabel_configs;
relabel_configs = commonProbeScrapeConfig.relabel_configs ++ [ {
source_labels = [ "__param_target" ];
regex = "https?://(.*)";
target_label = "domain";
} ];
static_configs = [ {
targets = opts.urls;
} ];
};
in lib.flatten (lib.foldl (x: probe: x ++ [
(lib.foldl (x: name: x ++ [
(lib.foldl (x: domain: x ++ [
(commonProbeScrapeConfig // {
job_name = "blackbox_dns_${probe.name}_${name}";
params.module = [ "dns_${probe.name}_${name}" ];
job_name = "blackbox_dns_${probe.name}_${domain}";
params.module = [ "dns_${probe.name}_${domain}" ];
static_configs = [ {
labels = { inherit domain; };
inherit (probe.value) targets;
} ];
})
]) [ ] probe.value.names)
]) [ ] probe.value.domains)
]) [ ] (lib.attrsToList cfgb.dnsProbe))

++ lib.filter (v: v != null) (lib.mapAttrsToList (name: opts:
if (opts.ip == "both" || opts.ip == "ip4") then (genHttpProbeScrapeConfig { inherit name opts; }) else null
) cfgb.httpProbe
Expand Down