97 lines
2.4 KiB
Nix
97 lines
2.4 KiB
Nix
{
|
|
modulesPath,
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
{
|
|
sops = {
|
|
secrets."services/loki/basic_auth" = {
|
|
mode = "0444";
|
|
owner = "nobody";
|
|
group = "nobody";
|
|
restartUnits = [ "alloy.service" ];
|
|
sopsFile = ../secrets/passwords.yaml;
|
|
};
|
|
secrets."services/mimir/basic_auth" = {
|
|
mode = "0444";
|
|
owner = "nobody";
|
|
group = "nobody";
|
|
restartUnits = [ "alloy.service" ];
|
|
sopsFile = ../secrets/passwords.yaml;
|
|
};
|
|
};
|
|
|
|
services.alloy = {
|
|
enable = true;
|
|
};
|
|
|
|
environment.etc."alloy/config.alloy" = {
|
|
text = ''
|
|
prometheus.remote_write "default" {
|
|
endpoint {
|
|
url = "http://mimir.noc.eh22.intern/api/v1/push"
|
|
basic_auth {
|
|
username = "noc"
|
|
password_file = "${config.sops.secrets."services/mimir/basic_auth".path}"
|
|
}
|
|
}
|
|
}
|
|
loki.write "default" {
|
|
endpoint {
|
|
url = "http://loki.noc.eh22.intern/loki/api/v1/push"
|
|
basic_auth {
|
|
username = "noc"
|
|
password_file = "${config.sops.secrets."services/loki/basic_auth".path}"
|
|
}
|
|
}
|
|
}
|
|
|
|
loki.relabel "journal" {
|
|
forward_to = []
|
|
|
|
rule {
|
|
source_labels = ["__journal__systemd_unit"]
|
|
target_label = "systemd_unit"
|
|
}
|
|
rule {
|
|
source_labels = ["__journal__hostname"]
|
|
target_label = "instance"
|
|
}
|
|
rule {
|
|
source_labels = ["__journal__transport"]
|
|
target_label = "systemd_transport"
|
|
}
|
|
rule {
|
|
source_labels = ["__journal_syslog_identifier"]
|
|
target_label = "syslog_identifier"
|
|
}
|
|
rule {
|
|
source_labels = ["__journal_priority_keyword"]
|
|
target_label = "level"
|
|
}
|
|
}
|
|
|
|
loki.source.journal "read_journal" {
|
|
forward_to = [loki.write.default.receiver]
|
|
relabel_rules = loki.relabel.journal.rules
|
|
format_as_json = true
|
|
labels = {component = "loki.source.journal", host = "${config.networking.hostName}"}
|
|
}
|
|
|
|
logging {
|
|
level = "warn"
|
|
format = "logfmt"
|
|
}
|
|
|
|
prometheus.exporter.unix "local_system" { }
|
|
|
|
prometheus.scrape "scrape_metrics" {
|
|
targets = prometheus.exporter.unix.local_system.targets
|
|
forward_to = [prometheus.remote_write.default.receiver]
|
|
scrape_interval = "10s"
|
|
}
|
|
'';
|
|
};
|
|
}
|