mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 15:11:34 +01:00
alloy: Actually implement the functionality
This commit is contained in:
parent
58e7ffce5c
commit
7fbb1de671
1 changed files with 51 additions and 0 deletions
|
|
@ -13,6 +13,18 @@ in
|
|||
type = lib.types.port;
|
||||
default = 12345;
|
||||
};
|
||||
metricsEndpoint = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
default = "https://metrics.${config.custom.services.tailscale.domain}/prometheus/api/v1/write";
|
||||
};
|
||||
logsEndpoint = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
default = "https://logs.${config.custom.services.tailscale.domain}/insert/loki/api/v1/push";
|
||||
};
|
||||
collect = {
|
||||
hostMetrics = lib.mkEnableOption "";
|
||||
sshdLogs = lib.mkEnableOption "";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
|
@ -28,5 +40,44 @@ in
|
|||
"--disable-reporting"
|
||||
];
|
||||
};
|
||||
|
||||
environment.etc = {
|
||||
"alloy/endpoints.alloy".text = ''
|
||||
prometheus.remote_write "default" {
|
||||
endpoint {
|
||||
url = "${cfg.metricsEndpoint}"
|
||||
}
|
||||
}
|
||||
|
||||
loki.write "default" {
|
||||
endpoint {
|
||||
url = "${cfg.logsEndpoint}"
|
||||
}
|
||||
}
|
||||
'';
|
||||
|
||||
"alloy/node-exporter.alloy" = lib.mkIf cfg.collect.hostMetrics {
|
||||
text = ''
|
||||
prometheus.exporter.unix "default" {
|
||||
enable_collectors = [ "systemd" ]
|
||||
}
|
||||
|
||||
prometheus.scrape "node_exporter" {
|
||||
targets = prometheus.exporter.unix.default.targets
|
||||
forward_to = [prometheus.remote_write.default.receiver]
|
||||
scrape_interval = "15s"
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
"alloy/sshd-logs.alloy" = lib.mkIf cfg.collect.sshdLogs {
|
||||
text = ''
|
||||
loki.source.journal "sshd" {
|
||||
matches = "_SYSTEMD_UNIT=sshd.service"
|
||||
forward_to = [loki.write.default.receiver]
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue