mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 16:21:34 +01:00
alloy: Enable endpoints conditionally based on requirements
This commit is contained in:
parent
9bc7a2e737
commit
3f85a77fc9
4 changed files with 75 additions and 61 deletions
|
|
@ -79,9 +79,9 @@
|
||||||
alloy = {
|
alloy = {
|
||||||
enable = true;
|
enable = true;
|
||||||
domain = "alloy-${config.networking.hostName}.${tailscaleDomain}";
|
domain = "alloy-${config.networking.hostName}.${tailscaleDomain}";
|
||||||
collect = {
|
collect.metrics = {
|
||||||
hostMetrics = true;
|
system = true;
|
||||||
victorialogsMetrics = true;
|
victorialogs = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
alloy = {
|
alloy = {
|
||||||
enable = true;
|
enable = true;
|
||||||
domain = "alloy-${config.networking.hostName}.${tailscaleDomain}";
|
domain = "alloy-${config.networking.hostName}.${tailscaleDomain}";
|
||||||
collect.hostMetrics = true;
|
collect.metrics.system = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts =
|
caddy.virtualHosts =
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,8 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
domain = "alloy-${config.networking.hostName}.${config.custom.services.tailscale.domain}";
|
domain = "alloy-${config.networking.hostName}.${config.custom.services.tailscale.domain}";
|
||||||
collect = {
|
collect = {
|
||||||
hostMetrics = true;
|
metrics.system = true;
|
||||||
sshdLogs = true;
|
logs.sshd = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,20 +22,22 @@ in
|
||||||
default = "https://logs.${config.custom.services.tailscale.domain}/insert/loki/api/v1/push";
|
default = "https://logs.${config.custom.services.tailscale.domain}/insert/loki/api/v1/push";
|
||||||
};
|
};
|
||||||
collect = {
|
collect = {
|
||||||
hostMetrics = lib.mkEnableOption "";
|
metrics = {
|
||||||
victorialogsMetrics = lib.mkEnableOption "";
|
system = lib.mkEnableOption "";
|
||||||
sshdLogs = lib.mkEnableOption "";
|
victorialogs = lib.mkEnableOption "";
|
||||||
|
};
|
||||||
|
logs.sshd = lib.mkEnableOption "";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
assertion = cfg.collect.victorialogsMetrics -> config.services.victorialogs.enable;
|
assertion = cfg.collect.metrics.victorialogs -> config.services.victorialogs.enable;
|
||||||
message = "Collecting VictoriaLogs metrics requires the VictoriaLogs service to be enabled.";
|
message = "Collecting VictoriaLogs metrics requires the VictoriaLogs service to be enabled.";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
assertion = cfg.collect.sshdLogs -> config.services.openssh.enable;
|
assertion = cfg.collect.logs.sshd -> config.services.openssh.enable;
|
||||||
message = "Collecting OpenSSH logs requires the OpenSSH service to be enabled.";
|
message = "Collecting OpenSSH logs requires the OpenSSH service to be enabled.";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
@ -53,22 +55,34 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.etc = {
|
environment.etc =
|
||||||
"alloy/endpoints.alloy".text = ''
|
let
|
||||||
|
isTrue = x: x;
|
||||||
|
anyIsTrue = attrs: attrs |> lib.attrValues |> lib.any isTrue;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
"alloy/metrics-endpoint.alloy" = {
|
||||||
|
enable = cfg.collect.metrics |> anyIsTrue;
|
||||||
|
text = ''
|
||||||
prometheus.remote_write "default" {
|
prometheus.remote_write "default" {
|
||||||
endpoint {
|
endpoint {
|
||||||
url = "${cfg.metricsEndpoint}"
|
url = "${cfg.metricsEndpoint}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
"alloy/logs-endpoint.alloy" = {
|
||||||
|
enable = cfg.collect.logs |> anyIsTrue;
|
||||||
|
text = ''
|
||||||
loki.write "default" {
|
loki.write "default" {
|
||||||
endpoint {
|
endpoint {
|
||||||
url = "${cfg.logsEndpoint}"
|
url = "${cfg.logsEndpoint}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
"alloy/host-metrics.alloy" = lib.mkIf cfg.collect.hostMetrics {
|
"alloy/system-metrics.alloy" = {
|
||||||
|
enable = cfg.collect.metrics.system;
|
||||||
text = ''
|
text = ''
|
||||||
prometheus.exporter.unix "default" {
|
prometheus.exporter.unix "default" {
|
||||||
enable_collectors = ["systemd"]
|
enable_collectors = ["systemd"]
|
||||||
|
|
@ -81,8 +95,8 @@ in
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
"alloy/victorialogs-metrics.alloy" = {
|
||||||
"alloy/victorialogs-metrics.alloy" = lib.mkIf cfg.collect.victorialogsMetrics {
|
enable = cfg.collect.metrics.victorialogs;
|
||||||
text = ''
|
text = ''
|
||||||
prometheus.scrape "victorialogs" {
|
prometheus.scrape "victorialogs" {
|
||||||
targets = [{
|
targets = [{
|
||||||
|
|
@ -95,8 +109,8 @@ in
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
"alloy/sshd-logs.alloy" = {
|
||||||
"alloy/sshd-logs.alloy" = lib.mkIf cfg.collect.sshdLogs {
|
enable = cfg.collect.logs.sshd;
|
||||||
text = ''
|
text = ''
|
||||||
loki.source.journal "sshd" {
|
loki.source.journal "sshd" {
|
||||||
matches = "_SYSTEMD_UNIT=sshd.service"
|
matches = "_SYSTEMD_UNIT=sshd.service"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue