2024-09-09 15:19:57 +02:00
|
|
|
{
|
2025-01-23 14:13:19 +01:00
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
cfg = config.services.vm_grafana;
|
|
|
|
in {
|
2024-09-09 15:19:57 +02:00
|
|
|
options.services.vm_grafana = {
|
|
|
|
enable = lib.mkEnableOption "Enable minimal config";
|
2024-10-23 15:52:13 +02:00
|
|
|
vm_ip = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The VM IP address";
|
|
|
|
};
|
2024-09-09 15:19:57 +02:00
|
|
|
proxy_ip = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The Nginx proxy IP address";
|
|
|
|
};
|
2024-09-25 13:44:15 +02:00
|
|
|
pgsql_ip = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The PostgreSQL host IP address";
|
|
|
|
};
|
2024-09-09 15:19:57 +02:00
|
|
|
};
|
2024-10-23 15:52:13 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2025-01-23 14:13:19 +01:00
|
|
|
age.secrets = {
|
2025-01-08 11:50:21 +01:00
|
|
|
grafana-db = {
|
2025-01-23 14:13:19 +01:00
|
|
|
file = ./secrets/grafana-db.age;
|
2025-01-08 11:50:21 +01:00
|
|
|
owner = "grafana";
|
|
|
|
};
|
|
|
|
grafana-oauth_secret = {
|
2025-01-23 14:13:19 +01:00
|
|
|
file = ./secrets/grafana-oauth_secret.age;
|
2025-01-08 11:50:21 +01:00
|
|
|
owner = "grafana";
|
|
|
|
};
|
2025-01-23 14:13:19 +01:00
|
|
|
kuma-token.file = ./secrets/kuma-token.age;
|
2024-10-23 15:52:13 +02:00
|
|
|
};
|
2024-10-07 12:23:45 +02:00
|
|
|
services.rsyslogd = {
|
|
|
|
enable = true;
|
|
|
|
extraConfig = ''
|
|
|
|
ruleset(name="remote"){
|
|
|
|
action(type="omfwd" Target="localhost" Port="1514" Protocol="tcp" Template="RSYSLOG_SyslogProtocol23Format" TCP_Framing="octet-counted")
|
|
|
|
}
|
|
|
|
|
|
|
|
module(load="imudp")
|
|
|
|
input(type="imudp" port="514" ruleset="remote")
|
|
|
|
|
|
|
|
module(load="imtcp")
|
|
|
|
input(type="imtcp" port="514" ruleset="remote")
|
|
|
|
'';
|
2025-01-08 11:50:21 +01:00
|
|
|
};
|
2024-10-07 16:36:30 +02:00
|
|
|
services.influxdb2 = {
|
|
|
|
enable = true;
|
2025-01-08 11:50:21 +01:00
|
|
|
};
|
2024-09-09 15:19:57 +02:00
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
server = {
|
|
|
|
protocol = "http";
|
2024-10-23 15:52:13 +02:00
|
|
|
http_addr = "${cfg.vm_ip}";
|
2024-09-09 15:19:57 +02:00
|
|
|
http_port = 3000;
|
|
|
|
domain = "logs.le43.eu";
|
|
|
|
root_url = "https://logs.le43.eu";
|
|
|
|
serve_from_sub_path = false;
|
|
|
|
};
|
2024-09-25 13:36:18 +02:00
|
|
|
database = {
|
2025-01-23 14:13:19 +01:00
|
|
|
type = "postgres";
|
|
|
|
host = "${cfg.pgsql_ip}:5432";
|
|
|
|
name = "grafana";
|
|
|
|
user = "grafana";
|
2024-10-23 16:45:46 +02:00
|
|
|
password = "\$__file{${config.age.secrets.grafana-db.path}}";
|
2024-09-25 12:56:59 +02:00
|
|
|
};
|
2025-01-08 11:50:21 +01:00
|
|
|
"auth.generic_oauth" = {
|
2025-01-23 14:13:19 +01:00
|
|
|
enabled = "true";
|
|
|
|
name = "authentik";
|
2025-01-08 12:57:14 +01:00
|
|
|
allow_sign_up = "true";
|
2025-01-23 14:13:19 +01:00
|
|
|
client_id = "9HV82G8F92Jcbw4nP8eppMcPpLcAw5uYpejfReLy";
|
2025-01-08 11:50:21 +01:00
|
|
|
client_secret = "\$__file{${config.age.secrets.grafana-oauth_secret.path}}";
|
2025-01-23 14:13:19 +01:00
|
|
|
scopes = "openid email profile";
|
|
|
|
auth_url = "https://authentik.le43.eu/application/o/authorize/";
|
|
|
|
token_url = "https://authentik.le43.eu/application/o/token/";
|
|
|
|
api_url = "https://authentik.le43.eu/application/o/userinfo/";
|
2025-01-08 12:57:14 +01:00
|
|
|
role_attribute_path = "contains(groups, 'admin') && 'Admin' || contains(groups, 'admin') && 'Editor' || 'Viewer';role_attribute_strict = false";
|
|
|
|
allow_assign_grafana_admin = "true";
|
2025-01-08 11:50:21 +01:00
|
|
|
};
|
2024-09-09 15:19:57 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
services.prometheus = {
|
|
|
|
enable = true;
|
|
|
|
port = 9001;
|
|
|
|
scrapeConfigs = [
|
2024-10-18 15:34:19 +02:00
|
|
|
{
|
|
|
|
job_name = "kuma";
|
|
|
|
scrape_interval = "30s";
|
|
|
|
scheme = "http";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.90:3001"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-18 15:34:19 +02:00
|
|
|
basic_auth.username = "tbarnouin";
|
2024-10-23 15:52:13 +02:00
|
|
|
basic_auth.password_file = config.age.secrets.kuma-token.path;
|
2024-10-18 15:34:19 +02:00
|
|
|
}
|
2024-09-09 15:19:57 +02:00
|
|
|
{
|
2024-10-18 16:06:42 +02:00
|
|
|
job_name = "grafana";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["127.0.0.1:9002"];
|
|
|
|
}
|
|
|
|
];
|
2024-09-09 15:19:57 +02:00
|
|
|
}
|
2024-10-18 15:52:52 +02:00
|
|
|
{
|
2024-10-18 16:06:42 +02:00
|
|
|
job_name = "openmediavault_cadvisor";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.125:8080"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-18 15:52:52 +02:00
|
|
|
}
|
2024-10-18 16:06:42 +02:00
|
|
|
{
|
2024-10-18 16:11:01 +02:00
|
|
|
job_name = "opportunity";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.125:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-18 16:06:42 +02:00
|
|
|
}
|
2024-09-09 15:19:57 +02:00
|
|
|
{
|
|
|
|
job_name = "nginx";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["${cfg.proxy_ip}:9002"];
|
|
|
|
}
|
|
|
|
];
|
2024-09-09 15:19:57 +02:00
|
|
|
}
|
2024-09-17 17:32:03 +02:00
|
|
|
{
|
|
|
|
job_name = "redis";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.16:9002"];
|
|
|
|
}
|
|
|
|
];
|
2024-09-17 17:32:03 +02:00
|
|
|
}
|
2024-10-07 17:49:44 +02:00
|
|
|
{
|
|
|
|
job_name = "ingenuity";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.90:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:49:44 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "gitea";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.14:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:49:44 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "postgresql";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.13:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:49:44 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "nextcloud";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.44:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:49:44 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "deluge";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.18:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:49:44 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "netbox";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.45:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:49:44 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "jellyfin";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.42:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:59:20 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "authentik-ldap";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.41:9100"];
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 17:49:44 +02:00
|
|
|
}
|
2024-09-17 17:32:03 +02:00
|
|
|
{
|
|
|
|
job_name = "authentik";
|
2025-01-23 14:13:19 +01:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["192.168.1.25:9002"];
|
|
|
|
}
|
|
|
|
];
|
2024-09-17 17:32:03 +02:00
|
|
|
}
|
2024-09-09 15:19:57 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
services.loki = {
|
|
|
|
enable = true;
|
|
|
|
configuration = {
|
|
|
|
server.http_listen_port = 3100;
|
|
|
|
server.grpc_listen_port = 9096;
|
|
|
|
auth_enabled = false;
|
|
|
|
ingester = {
|
|
|
|
lifecycler = {
|
|
|
|
address = "127.0.0.1";
|
|
|
|
ring = {
|
|
|
|
kvstore = {
|
|
|
|
store = "inmemory";
|
|
|
|
};
|
|
|
|
replication_factor = 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
chunk_idle_period = "1h";
|
|
|
|
max_chunk_age = "1h";
|
|
|
|
chunk_target_size = 999999;
|
|
|
|
chunk_retain_period = "30s";
|
|
|
|
};
|
|
|
|
schema_config = {
|
2025-01-23 14:13:19 +01:00
|
|
|
configs = [
|
|
|
|
{
|
|
|
|
from = "2022-06-06";
|
|
|
|
store = "boltdb-shipper";
|
|
|
|
object_store = "filesystem";
|
|
|
|
schema = "v13";
|
|
|
|
index = {
|
|
|
|
prefix = "index_";
|
|
|
|
period = "24h";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2024-09-09 15:19:57 +02:00
|
|
|
};
|
|
|
|
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";
|
|
|
|
allow_structured_metadata = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
table_manager = {
|
|
|
|
retention_deletes_enabled = false;
|
|
|
|
retention_period = "0s";
|
|
|
|
};
|
|
|
|
compactor = {
|
|
|
|
working_directory = "/var/lib/loki";
|
|
|
|
compactor_ring = {
|
|
|
|
kvstore = {
|
|
|
|
store = "inmemory";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
services.promtail = {
|
|
|
|
enable = true;
|
|
|
|
configuration = {
|
|
|
|
server = {
|
|
|
|
http_listen_port = 3101;
|
|
|
|
grpc_listen_port = 9095;
|
|
|
|
};
|
|
|
|
positions = {
|
|
|
|
filename = "/tmp/positions.yaml";
|
|
|
|
};
|
2025-01-23 14:13:19 +01:00
|
|
|
clients = [
|
|
|
|
{
|
|
|
|
url = "http://127.0.0.1:3100/loki/api/v1/push";
|
|
|
|
}
|
|
|
|
];
|
2024-10-07 12:23:45 +02:00
|
|
|
scrape_configs = [
|
|
|
|
{
|
|
|
|
job_name = "syslog";
|
|
|
|
syslog = {
|
2025-01-23 14:13:19 +01:00
|
|
|
listen_address = "0.0.0.0:1514";
|
2024-10-07 16:55:05 +02:00
|
|
|
listen_protocol = "tcp";
|
|
|
|
idle_timeout = "60s";
|
2024-10-07 12:23:45 +02:00
|
|
|
labels = {
|
|
|
|
job = "syslog";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
relabel_configs = [
|
|
|
|
{
|
2025-01-23 14:13:19 +01:00
|
|
|
source_labels = ["__syslog_message_hostname"];
|
2024-10-07 12:23:45 +02:00
|
|
|
target_label = "host";
|
|
|
|
}
|
|
|
|
{
|
2025-01-23 14:13:19 +01:00
|
|
|
source_labels = ["__syslog_message_hostname"];
|
2024-10-07 12:23:45 +02:00
|
|
|
target_label = "hostname";
|
|
|
|
}
|
|
|
|
{
|
2025-01-23 14:13:19 +01:00
|
|
|
source_labels = ["__syslog_message_severity"];
|
2024-10-07 12:23:45 +02:00
|
|
|
target_label = "level";
|
|
|
|
}
|
|
|
|
{
|
2025-01-23 14:13:19 +01:00
|
|
|
source_labels = ["__syslog_message_app_name"];
|
2024-10-07 12:23:45 +02:00
|
|
|
target_label = "application";
|
|
|
|
}
|
|
|
|
{
|
2025-01-23 14:13:19 +01:00
|
|
|
source_labels = ["__syslog_message_facility"];
|
2024-10-07 12:23:45 +02:00
|
|
|
target_label = "facility";
|
|
|
|
}
|
|
|
|
{
|
2025-01-23 14:13:19 +01:00
|
|
|
source_labels = ["__syslog_connection_hostname"];
|
2024-10-07 12:23:45 +02:00
|
|
|
target_label = "connection_hostname";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2024-09-09 15:19:57 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Open ports in the firewall.
|
2025-01-23 14:13:19 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [3000 3100 3101 8086 9001 1514 514];
|
|
|
|
networking.firewall.allowedUDPPorts = [514];
|
2024-09-09 15:19:57 +02:00
|
|
|
};
|
|
|
|
}
|