Prometheus extraScrapeConfigs as parameter

This commit is contained in:
pazpi 2026-01-15 14:56:24 +01:00
parent addd0c5df4
commit f20c086d6f
2 changed files with 32 additions and 21 deletions

View file

@ -21,6 +21,12 @@ in
file = ../../secrets/grafana-secret-auth.age; file = ../../secrets/grafana-secret-auth.age;
owner = "grafana"; owner = "grafana";
}; };
searx-prometheus-secret = {
file = ../../secrets/searx-prometheus-secret.age;
owner = config.users.users."prometheus".name;
group = config.users.groups."prometheus".name;
mode = "0644";
};
}; };
my = { my = {
@ -48,7 +54,23 @@ in
}; };
proxy.domain = p.domains.public; proxy.domain = p.domains.public;
}; };
prometheus.enable = true; prometheus = {
enable = true;
extraScrapeConfigs = [
{
job_name = "caddy";
static_configs = [ { targets = [ "${p.hosts.caddy}:2024" ]; } ];
}
{
job_name = "searxng";
static_configs = [ { targets = [ "${p.hosts.caddy}:8080" ]; } ];
basic_auth = {
username = "searxng";
password_file = config.age.secrets.searx-prometheus-secret.path;
};
}
];
};
loki.enable = true; loki.enable = true;
}; };

View file

@ -15,6 +15,14 @@ in
options.my.monitoring.prometheus = { options.my.monitoring.prometheus = {
enable = lib.mkEnableOption "Enable prometheus as a data scraper"; enable = lib.mkEnableOption "Enable prometheus as a data scraper";
extraScrapeConfigs = lib.mkOption {
default = [ ];
type = lib.types.listOf lib.types.attrs;
description = ''
Additional scrape configurations to add to Prometheus.
'';
};
proxy = { proxy = {
enable = lib.mkEnableOption "Set the proxy entry for this service"; enable = lib.mkEnableOption "Set the proxy entry for this service";
@ -49,13 +57,6 @@ in
config = lib.mkMerge [ config = lib.mkMerge [
(lib.mkIf cfg.enable { (lib.mkIf cfg.enable {
age.secrets.searx-prometheus-secret = {
file = ../../secrets/searx-prometheus-secret.age;
owner = config.users.users."prometheus".name;
group = config.users.groups."prometheus".name;
mode = "0644";
};
services.prometheus = { services.prometheus = {
enable = true; enable = true;
scrapeConfigs = [ scrapeConfigs = [
@ -73,19 +74,7 @@ in
} }
]; ];
} }
{ ] ++ cfg.extraScrapeConfigs;
job_name = "caddy";
static_configs = [ { targets = [ "caddy.internal:2024" ]; } ];
}
{
job_name = "searxng";
static_configs = [ { targets = [ "caddy.internal:8080" ]; } ];
basic_auth = {
username = "searxng";
password_file = config.age.secrets.searx-prometheus-secret.path;
};
}
];
}; };
services.grafana = { services.grafana = {