alloy: Add caddy metrics scraping

This commit is contained in:
SebastianStork 2025-09-22 00:28:47 +02:00
parent 926716e7e5
commit 1515ce28e4
4 changed files with 27 additions and 3 deletions

View file

@ -82,6 +82,7 @@
collect.metrics = {
system = true;
victorialogs = true;
caddy = true;
};
};

View file

@ -56,7 +56,10 @@
alloy = {
enable = true;
domain = "alloy-${config.networking.hostName}.${tailscaleDomain}";
collect.metrics.system = true;
collect.metrics = {
system = true;
caddy = true;
};
};
caddy.virtualHosts =

View file

@ -78,7 +78,10 @@
enable = true;
domain = "alloy-${config.networking.hostName}.${config.custom.services.tailscale.domain}";
collect = {
metrics.system = true;
metrics = {
system = true;
caddy = true;
};
logs.sshd = true;
};
};

View file

@ -25,6 +25,7 @@ in
metrics = {
system = lib.mkEnableOption "";
victorialogs = lib.mkEnableOption "";
caddy = lib.mkEnableOption "";
};
logs.sshd = lib.mkEnableOption "";
};
@ -36,6 +37,10 @@ in
assertion = cfg.collect.metrics.victorialogs -> config.services.victorialogs.enable;
message = "Collecting VictoriaLogs metrics requires the VictoriaLogs service to be enabled.";
}
{
assertion = cfg.collect.metrics.caddy -> config.services.caddy.enable;
message = "Collecting Caddy metrics requires the Caddy service to be enabled.";
}
{
assertion = cfg.collect.logs.sshd -> config.services.openssh.enable;
message = "Collecting OpenSSH logs requires the OpenSSH service to be enabled.";
@ -101,7 +106,19 @@ in
prometheus.scrape "victorialogs" {
targets = [{
__address__ = "localhost:${builtins.toString config.custom.services.victorialogs.port}",
job = "victorialogs",
instance = constants.hostname,
}]
forward_to = [prometheus.remote_write.default.receiver]
scrape_interval = "15s"
}
'';
};
"alloy/caddy-metrics.alloy" = {
enable = cfg.collect.metrics.caddy;
text = ''
prometheus.scrape "caddy" {
targets = [{
__address__ = "localhost:2019",
instance = constants.hostname,
}]
forward_to = [prometheus.remote_write.default.receiver]