87 lines
2.3 KiB
Nix
87 lines
2.3 KiB
Nix
{config, pkgs, ...}:{
|
|
sops = {
|
|
secrets = {
|
|
domainName = {
|
|
sopsFile = ../../../../secrets/net.yaml;
|
|
restartUnits = ["promtail.service"];
|
|
};
|
|
};
|
|
templates = {
|
|
promtail.content = ''
|
|
server:
|
|
# http_listen_port: 28183
|
|
http_listen_port: 0
|
|
grpc_listen_port: 0
|
|
|
|
positions:
|
|
filename: /var/tmp/positions.yaml
|
|
|
|
clients:
|
|
- url: https://logs.${config.sops.placeholder.domainName}/loki/api/v1/push
|
|
# no auth
|
|
tenant_id: ""
|
|
backoff_config:
|
|
min_period: 1000ms
|
|
# max_period: 10s
|
|
max_period: 5m
|
|
max_retries: 10000
|
|
|
|
scrape_configs:
|
|
- job_name: journal
|
|
journal:
|
|
#max_age: 168h
|
|
max_age: 14400h
|
|
labels:
|
|
job: systemd-journal
|
|
host: ${config.networking.hostName}
|
|
relabel_configs:
|
|
- source_labels: ["__journal__systemd_unit"]
|
|
target_label: "unit"
|
|
- source_labels: ['__journal__hostname']
|
|
target_label: nodename
|
|
- source_labels: ['__journal_syslog_identifier']
|
|
target_label: syslog_identifier
|
|
- action: drop
|
|
# drop this because of excessive logging
|
|
regex: '.*tailscale.*'
|
|
source_labels: ['__journal__systemd_unit', 'unit']
|
|
'';
|
|
};
|
|
};
|
|
|
|
systemd = {
|
|
services = {
|
|
promtail = {
|
|
description = "Promtail service for Loki";
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
serviceConfig = {
|
|
ExecStart = ''
|
|
${pkgs.grafana-loki}/bin/promtail --config.file ${config.sops.templates.promtail.path}
|
|
'';
|
|
TimeoutStopSec = "5s";
|
|
RestartSec = 90;
|
|
# Restart = "always";
|
|
Restart = "on-failure";
|
|
};
|
|
};
|
|
promtail-watcher = {
|
|
description = "Promtail watcher";
|
|
wantedBy = ["multi-user.target"];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
ExecStart = "systemctl restart promtail.service";
|
|
};
|
|
};
|
|
};
|
|
paths = {
|
|
promtail-watcher = {
|
|
pathConfig = {
|
|
PathChanged = config.sops.templates.promtail.path;
|
|
};
|
|
wantedBy = ["paths.target"];
|
|
};
|
|
};
|
|
};
|
|
}
|