Compare commits

...

27 commits

Author SHA1 Message Date
7bbacc8512
Try to diagnose Traefik metrics issue. 2026-02-14 20:10:54 +01:00
f84861132a
Re-enable the fowarding. 2026-02-14 19:32:48 +01:00
b4abbfaa27
Playing around settings.. 2026-02-14 19:12:47 +01:00
bcca1141b6
Another fix... 2026-02-14 19:03:33 +01:00
ba2cf5c149
Fixed some prometheus settings... again. 2026-02-14 19:02:24 +01:00
f7f0039f9c
Fixed some prometheus settings. 2026-02-14 19:00:12 +01:00
2665a2c0e5
Added initial infrastructure for declarative prometheus configs and established alloy integration for Traefik 2026-02-14 18:49:10 +01:00
d5920fb8fa
Averted the risk of lack of redirects. 2026-02-14 17:33:22 +01:00
19c7f994ed
Update port of Grafana. 2026-02-14 17:28:41 +01:00
6704bdcdfd
Update addresses. 2026-02-14 17:27:41 +01:00
c11896c50c
Properly convert document as per bbe11b0f6a/docs/sources/set-up/migrate/from-promtail.md 2026-02-14 17:19:21 +01:00
99c43c145e
Wrong format.. 2026-02-14 17:09:50 +01:00
a519b8ffec
Dangling wrong config. 2026-02-14 16:58:54 +01:00
75bf74d319
insane suffixes, fixed the broken suffix 2026-02-14 16:57:24 +01:00
458e085964
Derp by me - put the allow config call elsehwere it should be. 2026-02-14 16:54:45 +01:00
6bd1d4a231
Fix the broken environment call 2026-02-14 16:52:24 +01:00
21bf4848bb
Fix the Grafana Alloy 2026-02-14 16:48:24 +01:00
9363dc3b36
Odd issues... odd issues every where. 2026-02-14 16:36:56 +01:00
9bf4acd3bd
Remove unused and redundant Loki configuration options, why dry run does not find these. 2026-02-14 16:34:58 +01:00
85029b8507
Fix the Loki config 2026-02-14 16:32:30 +01:00
c65057ded3
Grafana Alloy and Loki Additions. 2026-02-14 16:25:46 +01:00
f771863d97
Oops, now I know more how Prometheus works. 2026-02-14 15:48:11 +01:00
0e902d7156
Play around with config options. 2026-02-14 15:36:14 +01:00
ff8ad94913
Configure Promethus Scrape Intefval 2026-02-14 15:25:25 +01:00
058fc0b667
Expose Grafana on port 3005 and add Traefik route with Anubis auth 2026-02-14 14:50:17 +01:00
35e5b04ad8
Temporarily disable Loki 2026-02-14 14:40:10 +01:00
e6b7a95b57
Add nixos-logs system with Grafana, Prometheus, and Loki; fix Traefik config formatting 2026-02-14 14:34:24 +01:00
5 changed files with 525 additions and 14 deletions

View file

@ -15,6 +15,7 @@ configs=(
"nixos-teamspeak"
"nixos-traefik"
"nixos-build-machine"
"nixos-logs"
)
if [[ -n "$1" ]]; then

View file

@ -52,6 +52,11 @@
inherit system;
modules = [./nix-system-configs/modules/system/build_machine.nix];
};
"nixos-logs" = nixpkgs.lib.nixosSystem {
inherit system;
modules = [./nix-system-configs/modules/system/gramethus.nix];
};
};
};
}

View file

@ -0,0 +1,223 @@
{
config,
pkgs,
lib,
...
}: let
choose = paths: lib.findFirst builtins.pathExists null paths;
# Dummy filesystem config for dry-run evaluation
dummyFileSystems = {
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
};
in {
options.local = {
hostname = lib.mkOption {
type = lib.types.str;
default = "nixos-default";
description = "System hostname";
};
username = lib.mkOption {
type = lib.types.str;
default = "user";
description = "Primary user username";
};
userDescription = lib.mkOption {
type = lib.types.str;
default = "NixOS User";
description = "Primary user description";
};
address = lib.mkOption {
type = lib.types.str;
default = "10.1.1.100";
description = "Static IP address";
};
};
imports =
lib.filter (x: x != null) [
(choose [./modules/local/hostname_username.nix ../local/hostname_username.nix])
(choose [./modules/local/networking_local.nix ../local/networking_local.nix])
(choose [./modules/bootloader/seabios-assigned-iso-at-birth.nix ../bootloader/seabios-assigned-iso-at-birth.nix])
(choose [./modules/lix-default.nix ../lix-default.nix])
(choose [./modules/secrets-config/sops-the-blank-system.nix ../secrets-config/sops-the-blank-system.nix])
]
# TODO: Make this more clean, migrate over to seabios-assigned-iso-at-birth.nix?
#++ lib.optional (builtins.pathExists ./hardware-configuration.nix) ./hardware-configuration.nix
#++ lib.optional (!builtins.pathExists ./hardware-configuration.nix) dummyFileSystems
;
config = {
local.hostname = "nixos-grametheus";
local.username = "prglogs";
local.userDescription = "NixOS PRG Grafana Prometheus Service";
local.address = "10.1.1.10";
system.stateVersion = "25.11";
services.grafana = {
enable = true;
settings = {
server = {
http_addr = "10.1.1.10";
http_port = 3000;
#enforce_domain = true;
enable_gzip = true;
domain = "grafana.prg-radio.org";
# Alternatively, if you want to serve Grafana from a subpath:
# domain = "your.domain";
# root_url = "https://your.domain/grafana/";
# serve_from_sub_path = true;
};
# Prevents Grafana from phoning home
#analytics.reporting_enabled = false;
};
};
services.prometheus = {
enable = true;
port = 9001;
exporters.node = {
enabledCollectors = [
"ethtool"
"softirqs"
"systemd"
"tcpstat"
];
enable = true;
port = 9002;
};
globalConfig.scrape_interval = "10s"; # "1m"
scrapeConfigs = [
{
job_name = "node";
static_configs = [
{
targets = ["localhost:${toString config.services.prometheus.exporters.node.port}"];
}
];
}
];
};
services.loki = {
enable = true;
configuration = {
auth_enabled = false;
server = {
http_listen_port = 3100;
};
ingester = {
lifecycler = {
address = "0.0.0.0";
ring = {
kvstore = {
store = "inmemory";
};
replication_factor = 1;
};
final_sleep = "0s";
};
chunk_idle_period = "1h";
max_chunk_age = "1h";
chunk_target_size = 1048576;
chunk_retain_period = "30s";
};
schema_config = {
configs = [
{
from = "2020-10-24";
store = "boltdb-shipper";
object_store = "filesystem";
schema = "v11";
index = {
prefix = "index_";
period = "24h";
};
}
];
};
storage_config = {
boltdb_shipper = {
active_index_directory = "/var/lib/loki/boltdb-shipper-active";
cache_location = "/var/lib/loki/boltdb-shipper-cache";
cache_ttl = "24h";
};
filesystem = {
directory = "/var/lib/loki/chunks";
};
};
limits_config = {
reject_old_samples = true;
reject_old_samples_max_age = "168h";
# Disable structured metadata/OTLP native ingestion until schema is upgraded to v13+ and tsdb index is used.
allow_structured_metadata = false;
};
table_manager = {
retention_deletes_enabled = false;
retention_period = "0s";
};
};
};
services.alloy = {
enable = true;
};
# See: https://github.com/grafana/alloy/blob/bbe11b0f6a3bd3391108b2d27122c654c535dd8d/docs/sources/set-up/migrate/from-promtail.md
environment.etc."alloy/config.alloy" = {
text = ''
discovery.relabel "journal" {
targets = []
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
}
loki.source.journal "journal" {
max_age = "12h0m0s"
relabel_rules = discovery.relabel.journal.rules
forward_to = [loki.write.default.receiver]
labels = {
host = "chrysalis",
job = "systemd-journal",
}
}
loki.write "default" {
endpoint {
url = "http://127.0.0.1:3100/loki/api/v1/push"
}
external_labels = {}
}
'';
group = "root";
mode = "0644";
};
# or alternatively
#configFile = ./loki-config.yaml;
# };
# Enable Tailscale for remote access to Traefik dashboard and configuration
services.tailscale.enable = true;
networking.firewall.allowedTCPPorts = [3000];
networking.firewall.allowedUDPPorts = [3000];
# ============== Declarative Config ================
};
}

View file

@ -58,7 +58,7 @@ in {
TARGET = " ";
# Configure redirect domains - ALL domains that should be able to redirect back after challenge
REDIRECT_DOMAINS = "prg-radio.org,anubis.prg-radio.org,git.prg-radio.org,lgbtq.prg-radio.org,wavelog.prg-radio.org,partdb.prg-radio.org";
REDIRECT_DOMAINS = "prg-radio.org,anubis.prg-radio.org,git.prg-radio.org,lgbtq.prg-radio.org,wavelog.prg-radio.org,partdb.prg-radio.org,grafana.prg-radio.org";
# Public URL for Anubis
PUBLIC_URL = "https://anubis.prg-radio.org";
@ -78,7 +78,7 @@ in {
# Prevents infinite loop of doom:
# See: https://github.com/TecharoHQ/anubis/issues/970
JWT_RESTRICTION_HEADER="CF-Connecting-IP";
JWT_RESTRICTION_HEADER = "CF-Connecting-IP";
# Metrics on separate port
METRICS_BIND_NETWORK = "tcp";
@ -90,14 +90,142 @@ in {
COOKIE_SAME_SITE = "None"; # Only if Secure=true and you need cross-site
};
};
};
};
services.loki = {
enable = true;
configuration = {
auth_enabled = false;
server = {
http_listen_port = 3100;
};
ingester = {
lifecycler = {
address = "0.0.0.0";
ring = {
kvstore = {
store = "inmemory";
};
replication_factor = 1;
};
final_sleep = "0s";
};
chunk_idle_period = "1h";
max_chunk_age = "1h";
chunk_target_size = 1048576;
chunk_retain_period = "30s";
};
schema_config = {
configs = [
{
from = "2020-10-24";
store = "boltdb-shipper";
object_store = "filesystem";
schema = "v11";
index = {
prefix = "index_";
period = "24h";
};
}
];
};
storage_config = {
boltdb_shipper = {
active_index_directory = "/var/lib/loki/boltdb-shipper-active";
cache_location = "/var/lib/loki/boltdb-shipper-cache";
cache_ttl = "24h";
};
filesystem = {
directory = "/var/lib/loki/chunks";
};
};
limits_config = {
reject_old_samples = true;
reject_old_samples_max_age = "168h";
# Disable structured metadata/OTLP native ingestion until schema is upgraded to v13+ and tsdb index is used.
allow_structured_metadata = false;
};
table_manager = {
retention_deletes_enabled = false;
retention_period = "0s";
};
};
};
services.alloy = {
enable = true;
};
services.prometheus = {
enable = true;
port = 9001;
exporters.node = {
enabledCollectors = [
"ethtool"
"softirqs"
"systemd"
"tcpstat"
];
enable = true;
port = 9002;
};
globalConfig.scrape_interval = "5s"; # "1m"
scrapeConfigs = [
{
job_name = "traefik";
static_configs = [
{
targets = ["localhost:8080"];
}
];
}
];
};
# See: https://github.com/grafana/alloy/blob/bbe11b0f6a3bd3391108b2d27122c654c535dd8d/docs/sources/set-up/migrate/from-promtail.md
environment.etc."alloy/config.alloy" = {
text = ''
discovery.relabel "metrics_integrations_integrations_traefik" {
targets = [{
__address__ = "localhost:8080",
}]
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "metrics_integrations_integrations_traefik" {
targets = discovery.relabel.metrics_integrations_integrations_traefik.output
job_name = "integrations/traefik"
}
'';
group = "root";
mode = "0644";
};
services.traefik = {
enable = true;
group = "acme";
staticConfigOptions = {
metrics = {
prometheus = {
addEntryPointsLabels = true;
addRoutersLabels = true;
addServicesLabels = true;
buckets = [0.1 0.3 1.2 5.0];
};
};
entryPoints = {
web = {
# Bind on IPv6 as well as IPv4 by using [::]:80
@ -174,9 +302,9 @@ in {
anubis = {
rule = "Host(`anubis.prg-radio.org`)";
service = "anubis";
entryPoints = [ "websecure" ];
entryPoints = ["websecure"];
tls = {
certresolver = "acme";
certresolver = "acme";
};
};
@ -184,16 +312,16 @@ in {
forgejo = {
rule = "Host(`git.prg-radio.org`)";
service = "forgejo";
entryPoints = [ "websecure" ];
entryPoints = ["websecure"];
tls = {};
middlewares = [ "anubisForwardAuth" ];
middlewares = ["anubisForwardAuth"];
};
# Matrix HTTP router for client requests (Element etc.)
matrix = {
rule = "Host(`lgbtq.prg-radio.org`)";
service = "matrix";
entryPoints = [ "websecure" ];
entryPoints = ["websecure"];
tls = {};
};
@ -201,7 +329,7 @@ in {
wavelog = {
rule = "Host(`wavelog.prg-radio.org`)";
service = "wavelog";
entryPoints = [ "websecure" ];
entryPoints = ["websecure"];
tls = {};
};
@ -209,9 +337,18 @@ in {
partdb = {
rule = "Host(`partdb.prg-radio.org`)";
service = "partdb";
entryPoints = [ "websecure" ];
entryPoints = ["websecure"];
tls = {};
middlewares = [ "anubisForwardAuth" ];
middlewares = ["anubisForwardAuth"];
};
# Protected service: Grafana
grafana = {
rule = "Host(`grafana.prg-radio.org`)";
service = "grafana";
entryPoints = ["websecure"];
tls = {};
middlewares = ["anubisForwardAuth"];
};
};
@ -244,6 +381,12 @@ in {
{url = "http://10.1.1.249:8087";}
];
};
grafana.loadBalancer = {
servers = [
{url = "http://10.1.1.10:3000";}
];
};
};
# TCP routing for TeamSpeak
@ -339,9 +482,9 @@ in {
wants = ["acme-finished-prg-radio.org.target"];
};
networking.firewall.allowedTCPPorts = [80 443 10022 30033 8448];
networking.firewall.allowedUDPPorts = [80 443 9987];
networking.firewall.allowedTCPPorts = [80 443 10022 30033 8448 9001 3001];
networking.firewall.allowedUDPPorts = [80 443 9987 9001 3001];
system.stateVersion = "25.11";
};
}
}

View file

@ -0,0 +1,139 @@
{
config,
pkgs,
lib,
...
}: {
services.prometheus = {
enable = true;
port = 9001;
exporters.node = {
enabledCollectors = [
"ethtool"
"softirqs"
"systemd"
"tcpstat"
];
enable = true;
port = 9002;
};
globalConfig.scrape_interval = "10s"; # "1m"
scrapeConfigs = [
{
job_name = "node";
static_configs = [
{
targets = ["localhost:${toString config.services.prometheus.exporters.node.port}"];
}
];
}
];
};
services.loki = {
enable = true;
configuration = {
auth_enabled = false;
server = {
http_listen_port = 3100;
};
ingester = {
lifecycler = {
address = "0.0.0.0";
ring = {
kvstore = {
store = "inmemory";
};
replication_factor = 1;
};
final_sleep = "0s";
};
chunk_idle_period = "1h";
max_chunk_age = "1h";
chunk_target_size = 1048576;
chunk_retain_period = "30s";
};
schema_config = {
configs = [
{
from = "2020-10-24";
store = "boltdb-shipper";
object_store = "filesystem";
schema = "v11";
index = {
prefix = "index_";
period = "24h";
};
}
];
};
storage_config = {
boltdb_shipper = {
active_index_directory = "/var/lib/loki/boltdb-shipper-active";
cache_location = "/var/lib/loki/boltdb-shipper-cache";
cache_ttl = "24h";
};
filesystem = {
directory = "/var/lib/loki/chunks";
};
};
limits_config = {
reject_old_samples = true;
reject_old_samples_max_age = "168h";
# Disable structured metadata/OTLP native ingestion until schema is upgraded to v13+ and tsdb index is used.
allow_structured_metadata = false;
};
table_manager = {
retention_deletes_enabled = false;
retention_period = "0s";
};
};
};
services.alloy = {
enable = true;
};
# See: https://github.com/grafana/alloy/blob/bbe11b0f6a3bd3391108b2d27122c654c535dd8d/docs/sources/set-up/migrate/from-promtail.md
environment.etc."alloy/config.alloy" = {
text = ''
discovery.relabel "journal" {
targets = []
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
}
loki.source.journal "journal" {
max_age = "12h0m0s"
relabel_rules = discovery.relabel.journal.rules
forward_to = [loki.write.default.receiver]
labels = {
host = "chrysalis",
job = "systemd-journal",
}
}
loki.write "default" {
endpoint {
url = "http://127.0.0.1:3100/loki/api/v1/push"
}
external_labels = {}
}
'';
group = "root";
mode = "0644";
};
networking.firewall.allowedTCPPorts = [3100 9001];
networking.firewall.allowedUDPPorts = [3100 9001];
}