Skip to content

Commit f0a8755

Browse files
Merge pull request #256 from NuschtOS/blackbox-improv
Various blackbox exporter improvements
2 parents ec11635 + dda2067 commit f0a8755

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

modules/prometheus.nix

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ in
2929
dnsProbe = lib.mkOption {
3030
type = with lib.types; attrsOf (submodule {
3131
options = {
32-
names = lib.mkOption {
32+
domains = lib.mkOption {
3333
type = with lib.types; listOf str;
3434
example = [ "example.com" ];
3535
description = "Query name to query";
@@ -109,17 +109,17 @@ in
109109
exporters.blackbox = {
110110
config.modules = lib.mkMerge (
111111
(lib.mapAttrsToList (probeName: opts:
112-
(lib.foldl (x: name: x // {
113-
"dns_${probeName}_${name}" = {
112+
(lib.foldl (x: domain: x // {
113+
"dns_${probeName}_${domain}" = {
114114
dns = {
115-
query_name = name;
115+
query_name = domain;
116116
query_type = opts.type;
117117
valid_rcodes = [ "NOERROR" ];
118118
};
119119
prober = "dns";
120120
timeout = "5s";
121121
};
122-
}) { } opts.names)
122+
}) { } opts.domains)
123123
) cfgb.dnsProbe)
124124

125125
++ lib.mapAttrsToList (name: opts: let
@@ -162,34 +162,42 @@ in
162162
metrics_path = "/probe";
163163
relabel_configs = [ {
164164
source_labels = [ "__address__" ];
165-
target_label = "__param_target";
165+
target_label = "__param_target"; # __param_* will be rewritten as query string
166166
} {
167167
source_labels = [ "__param_target" ];
168168
target_label = "instance";
169169
} {
170+
# needed because blackbox exporter (ab)uses targets for its targets but we actually need to ask the exporter about the target state
170171
target_label = "__address__";
171172
replacement = cfgb.blackboxExporterURL;
172173
} ];
173174
};
175+
174176
genHttpProbeScrapeConfig = { name, opts }: commonProbeScrapeConfig // {
175177
job_name = "blackbox_http_${name}";
176178
params.module = [ "http_${name}" ];
177-
inherit (commonProbeScrapeConfig) relabel_configs;
179+
relabel_configs = commonProbeScrapeConfig.relabel_configs ++ [ {
180+
source_labels = [ "__param_target" ];
181+
regex = "https?://(.*)";
182+
target_label = "domain";
183+
} ];
178184
static_configs = [ {
179185
targets = opts.urls;
180186
} ];
181187
};
182188
in lib.flatten (lib.foldl (x: probe: x ++ [
183-
(lib.foldl (x: name: x ++ [
189+
(lib.foldl (x: domain: x ++ [
184190
(commonProbeScrapeConfig // {
185-
job_name = "blackbox_dns_${probe.name}_${name}";
186-
params.module = [ "dns_${probe.name}_${name}" ];
191+
job_name = "blackbox_dns_${probe.name}_${domain}";
192+
params.module = [ "dns_${probe.name}_${domain}" ];
187193
static_configs = [ {
194+
labels = { inherit domain; };
188195
inherit (probe.value) targets;
189196
} ];
190197
})
191-
]) [ ] probe.value.names)
198+
]) [ ] probe.value.domains)
192199
]) [ ] (lib.attrsToList cfgb.dnsProbe))
200+
193201
++ lib.filter (v: v != null) (lib.mapAttrsToList (name: opts:
194202
if (opts.ip == "both" || opts.ip == "ip4") then (genHttpProbeScrapeConfig { inherit name opts; }) else null
195203
) cfgb.httpProbe

0 commit comments

Comments
 (0)