alloy: Push metrics to prometheus instead of victoriametrics

This commit is contained in:
SebastianStork 2026-02-28 23:47:15 +01:00
parent 1b599abdbe
commit 8f6f63fbaa
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q
2 changed files with 26 additions and 13 deletions

View file

@ -1,4 +1,9 @@
{ config, lib, ... }:
{
config,
lib,
allHosts,
...
}:
let
cfg = config.custom.services.alloy;
in
@ -13,10 +18,6 @@ in
type = lib.types.port;
default = 12345;
};
metricsEndpoint = lib.mkOption {
type = lib.types.nonEmptyStr;
default = "https://metrics.${config.custom.networking.overlay.domain}/prometheus/api/v1/write";
};
collect.metrics = {
system = lib.mkEnableOption "" // {
default = true;
@ -47,19 +48,30 @@ in
environment.etc =
let
isTrue = x: x;
anyIsTrue = attrs: attrs |> lib.attrValues |> lib.any isTrue;
anyIsTrue = attrs: attrs |> lib.attrValues |> lib.any lib.id;
prometheusEndpoints =
allHosts
|> lib.attrValues
|> lib.filter (host: host.config.custom.services.prometheus.enable)
|> lib.map (host: "https://${host.config.custom.services.prometheus.domain}/api/v1/write");
in
{
"alloy/metrics-endpoint.alloy" = {
enable = cfg.collect.metrics |> anyIsTrue;
text = ''
prometheus.remote_write "default" {
text =
prometheusEndpoints
|> lib.map (url: ''
endpoint {
url = "${cfg.metricsEndpoint}"
url = "${url}"
}
'')
|> lib.concatLines
|> (endpoints: ''
prometheus.remote_write "default" {
${endpoints}
}
'';
'');
};
"alloy/system-metrics.alloy" = {
enable = cfg.collect.metrics.system;
@ -85,7 +97,7 @@ in
instance = constants.hostname,
}]
forward_to = [prometheus.remote_write.default.receiver]
scrape_interval = "15s"
scrape_interval = "30s"
}
'';
};

View file

@ -30,6 +30,7 @@ in
inherit (cfg) port;
webExternalUrl = "https://${cfg.domain}";
extraFlags = [ "--web.enable-remote-write-receiver" ];
globalConfig = {
scrape_interval = "30s";
external_labels.monitor = "global";