Compare commits

...

4 Commits

Author SHA1 Message Date
Xavier Morel
4035967f21 fix: fix default journal logger integration 2025-11-16 00:57:21 +01:00
Xavier Morel
7f8f83271a feat: a bit of cleanup & keeping 15 days of metrics/logs 2025-11-16 00:20:05 +01:00
Xavier Morel
6578f1a626 feat: cleaning up some metrics & adding labels 2025-11-15 22:37:50 +01:00
Xavier Morel
eff961ff24 feat: fix logging config on dns 2025-11-15 20:15:55 +01:00
15 changed files with 103 additions and 91 deletions

View File

@@ -18,6 +18,7 @@
country_code = "eu"; country_code = "eu";
currency = "EUR"; currency = "EUR";
dns_provider = "cloudflare"; dns_provider = "cloudflare";
retention = "15d";
other_hosts = [ other_hosts = [
{ {

View File

@@ -27,15 +27,31 @@
prometheus.relabel "filter_metrics" { prometheus.relabel "filter_metrics" {
rule { rule {
action = "drop" source_labels = ["__name__"]
source_labels = [ "env" ] regex = ".*_build_info"
regex = "dev" action = "drop"
} }
rule { rule {
action = "replace" source_labels = ["__name__"]
regex = "127\\.0\\.0\\.1" regex = "go_.*"
target_label = "instance" action = "drop"
replacement = "${tools.build_ip container}" }
rule {
source_labels = [ "env" ]
regex = "dev"
action = "drop"
}
rule {
target_label = "host"
replacement = "${tools.build_hostname container}"
}
rule {
target_label = "host_ip"
replacement = "${tools.build_ip container}"
}
rule {
target_label = "service"
replacement = "alloy"
} }
forward_to = [prometheus.remote_write.metrics_service.receiver] forward_to = [prometheus.remote_write.metrics_service.receiver]
} }

View File

@@ -1,54 +0,0 @@
{ config, tools, ... }:
let
hostname = tools.build_hostname "proxy";
ip = tools.build_ip "proxy";
in
{
out = ''
loki.relabel "trf_journal" {
forward_to = []
rule {
source_labels = ["__journal__priority_keyword"]
target_label = "level"
}
rule {
source_labels = ["__journal__SYSLOG_IDENTIFIER"]
target_label = "app"
}
}
loki.source.journal "trf_journal_scrape" {
forward_to = [loki.process.trf_router.receiver]
matches = "_SYSTEMD_UNIT=traefik.service"
relabel_rules = loki.relabel.trf_journal.rules
labels = {
service = "traefik",
host = "${hostname}",
host_ip = "${ip}",
}
}
loki.process "trf_router" {
stage.regex {
expression = "^(?P<datetime>\\S+) (?P<level>\\w{3}) (?P<message>.*)$"
}
stage.timestamp {
source = "datetime"
format = "2006-01-02 15:04:05-07:00"
}
stage.replace {
source = "level"
expression = "INF"
replace = "INFO"
}
stage.labels {
values = {
level = "level",
}
}
stage.output {
source = "message"
}
forward_to = [loki.write.grafana_loki.receiver]
}
'';
}

View File

@@ -26,7 +26,8 @@ in
stage.timestamp { stage.timestamp {
source = "timestamp" source = "timestamp"
format = "2006-01-02 15:04:05" format = "2006/01/02 15:04:05.999999"
location = "${config.globals.default_tz}"
} }
stage.labels { stage.labels {

View File

@@ -7,7 +7,7 @@ let
mask_cidr = tools.mask_cidr; # build_ip_cidr 0 config.globals.cidr; mask_cidr = tools.mask_cidr; # build_ip_cidr 0 config.globals.cidr;
in in
{ {
environment.etc."alloy/logs-adguardhome.alloy".text = environment.etc."alloy/logs-unbound.alloy".text =
(import ./alloy/default-journal-logger.alloy.nix { (import ./alloy/default-journal-logger.alloy.nix {
inherit tools; inherit tools;
container = "dns"; container = "dns";

View File

@@ -13,6 +13,7 @@ in
extraFlags = [ extraFlags = [
"--web.enable-otlp-receiver" "--web.enable-otlp-receiver"
"--web.enable-remote-write-receiver" "--web.enable-remote-write-receiver"
"--storage.tsdb.retention.time=${config.globals.retention}"
]; ];
globalConfig = { globalConfig = {
scrape_interval = "30s"; scrape_interval = "30s";
@@ -21,7 +22,14 @@ in
{ {
job_name = "prometheus"; job_name = "prometheus";
static_configs = [ static_configs = [
{ targets = [ "localhost:9090" ]; } {
targets = [ "localhost:9090" ];
labels = {
host = tools.build_hostname "metrics";
host_ip = tools.build_ip "metrics";
service = "prometheus";
};
}
]; ];
} }
] ]
@@ -33,8 +41,13 @@ in
in in
{ {
job_name = container; job_name = container;
static_configs = map (port: { static_configs = lib.mapAttrsToList (service: port: {
targets = [ "${container_ip}:${toString port}" ]; targets = [ "${container_ip}:${toString port}" ];
labels = {
host = tools.build_hostname container;
host_ip = tools.build_ip container;
service = service;
};
}) def.logging.prometheusPorts; }) def.logging.prometheusPorts;
} }
) config.my-lxc ) config.my-lxc

View File

@@ -29,9 +29,13 @@
kvstore.store = "inmemory"; kvstore.store = "inmemory";
}; };
replication_factor = 1; replication_factor = 1;
path_prefix = "/tmp/loki"; path_prefix = "/var/lib/loki";
};
storage_config.filesystem.directory = "/var/lib/loki/chunks";
table_manager = {
retention_deletes_enabled = true;
retention_period = config.globals.retention;
}; };
storage_config.filesystem.directory = "/tmp/loki/chunks";
}; };
}; };
} }

View File

@@ -16,6 +16,15 @@ let
]; ];
in in
{ {
# environment.etc."alloy/logs-traefik.alloy".text =
# (import ./alloy/default-journal-logger.alloy.nix {
# inherit tools;
# container = "proxy";
# service = "traefik";
#
# '';
# }).out;
services = { services = {
traefik = { traefik = {
enable = true; enable = true;

View File

@@ -5,7 +5,7 @@
... ...
}: }:
{ {
environment.etc."yarrr.env".source = config.age.secrets.yarrr-env; environment.etc."yarrr.env".source = config.age.secrets.yarrr-env.path;
services = { services = {
bazarr = { bazarr = {

View File

@@ -24,7 +24,9 @@
logging = { logging = {
enable = true; enable = true;
metricsEnable = true; metricsEnable = true;
prometheusPorts = [ 9187 ]; prometheusPorts = {
postgres = 9187;
};
}; };
private = true; private = true;
auth = true; auth = true;

View File

@@ -24,9 +24,9 @@
logging = { logging = {
enable = true; enable = true;
metricsEnable = true; metricsEnable = true;
prometheusPorts = [ prometheusPorts = {
9167 unbound = 9167;
]; };
}; };
private = true; private = true;
auth = true; auth = true;

View File

@@ -22,10 +22,30 @@
logging = { logging = {
enable = true; enable = true;
metricsEnable = true; metricsEnable = true;
alloyConfig = { prometheusPorts.traefik = 8082;
# probably move to default-journal... journalLoggers.traefik = ''
"logs-traefik" = ../config/alloy/proxy-traefik.alloy.nix; stage.regex {
}; expression = "^(?P<client_ip>\\S+) (?P<ident>\\S+) (?P<auth_id>\\S+) \\[(?P<timestamp>[^\\]]+)\\] \"(?P<method>\\S+) (?P<path>\\S+) HTTP/(?P<http_version>\\S+)\" (?P<status>\\d+) (?P<bytes_sent>\\d+) \"(?P<referrer>[^\"]*)\" \"(?P<user_agent>[^\"]*)\" (?P<bytes_received>\\d+) \"(?P<router>[^\"]*)\" \"(?P<upstream>[^\"]*)\" (?P<duration>\\d+)ms$"
}
stage.timestamp {
source = "timestamp"
format = "02/Jan/2006:15:04:05 -0700"
}
stage.labels {
values = {
client_ip = "",
ident = "",
auth_id = "",
method = "",
status = "",
referrer = "",
router = "",
upstream = "",
}
}
'';
}; };
private = true; private = true;
auth = true; auth = true;

View File

@@ -30,9 +30,9 @@ in
logging = { logging = {
enable = true; enable = true;
metricsEnable = true; metricsEnable = true;
prometheusPorts = [ prometheusPorts = {
9708 yarrr = 9708;
]; };
}; };
otherDomains = [ otherDomains = [
{ {

View File

@@ -34,15 +34,14 @@ in
}) def.logging.alloyConfig) }) def.logging.alloyConfig)
++ (lib.mapAttrsToList (service: additional_stages: { ++ (lib.mapAttrsToList (service: additional_stages: {
"alloy/${container}-${service}.alloy".text = "alloy/${container}-${service}.alloy".text =
import ../config/alloy/default-journal-logger.alloy.nix (import ../config/alloy/default-journal-logger.alloy.nix {
{ inherit
inherit tools
tools container
container service
service additional_stages
additional_stages ;
; }).out;
};
}) def.logging.journalLoggers) }) def.logging.journalLoggers)
); );

View File

@@ -142,9 +142,9 @@ in
enable = mkEnableOption "Whether to enable default logs collection"; enable = mkEnableOption "Whether to enable default logs collection";
metricsEnable = mkEnableOption "Whether to enable default metrics collection"; metricsEnable = mkEnableOption "Whether to enable default metrics collection";
prometheusPorts = mkOption { prometheusPorts = mkOption {
type = listOf int; type = attrsOf int;
description = "Ports of Prometheus Exporters"; description = "Service => ports of Prometheus Exporters";
default = [ ]; default = { };
}; };
alloyConfig = mkOption { alloyConfig = mkOption {
type = attrsOf path; type = attrsOf path;
@@ -240,6 +240,7 @@ in
default_tz = mkOption { type = str; }; default_tz = mkOption { type = str; };
country_code = mkOption { type = str; }; country_code = mkOption { type = str; };
currency = mkOption { type = str; }; currency = mkOption { type = str; };
retention = mkOption { type = str; };
services = mkOption { services = mkOption {
type = submodule { type = submodule {
log_sink = mkOption { type = str; }; # ip:port log_sink = mkOption { type = str; }; # ip:port