self-hosting/modules/grafana.nix

184 lines
4.7 KiB
Nix
Raw Normal View History

2024-03-26 23:37:53 +01:00
{ config, lib, ... }:
let cfg = config.custom.services.grafana;
in {
options.custom.services.grafana = { enable = lib.mkEnableOption "grafana"; };
config = lib.mkIf cfg.enable {
sops.secrets = {
grafanaAdminPassword = {
owner = config.users.users.grafana.name;
key = "grafana/admin_password";
2022-12-02 03:29:02 +01:00
};
};
2024-03-26 23:37:53 +01:00
services.grafana = {
2022-09-15 21:42:58 +02:00
enable = true;
2024-03-26 23:37:53 +01:00
dataDir = "/nix/var/data/grafana";
settings = {
server = { domain = "grafana.${config.networking.domain}"; };
security.admin_password =
"$__file{${config.sops.secrets.grafanaAdminPassword.path}}";
2022-12-02 03:29:02 +01:00
};
2024-03-26 23:37:53 +01:00
provision = {
enable = true;
datasources.settings = {
datasources = [
{
name = "Prometheus";
type = "prometheus";
url =
"http://127.0.0.1:${toString config.services.prometheus.port}";
isDefault = true;
}
{
name = "Loki";
type = "loki";
access = "proxy";
url = "http://127.0.0.1:${
toString
config.services.loki.configuration.server.http_listen_port
}";
}
];
};
dashboards.settings.providers = [{
2022-09-15 21:42:58 +02:00
name = "Config";
options.path = ./dashboards;
2024-03-26 23:37:53 +01:00
}];
};
2022-09-15 21:42:58 +02:00
};
2024-03-26 23:37:53 +01:00
services.nginx = {
virtualHosts = {
"${config.services.grafana.settings.server.domain}" = {
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
enableACME = true;
forceSSL = true;
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
locations."/" = {
proxyPass = "http://127.0.0.1:${
toString config.services.grafana.settings.server.http_port
}";
proxyWebsockets = true;
};
2022-09-15 21:42:58 +02:00
};
};
};
2024-03-26 23:37:53 +01:00
services.prometheus = {
enable = true;
scrapeConfigs = [
{
job_name = "node";
static_configs = [{
targets = [
"10.0.2.3:${
toString config.services.prometheus.exporters.node.port
}"
"10.0.1.1:${
toString config.services.prometheus.exporters.node.port
}"
"10.0.1.11:${
toString config.services.prometheus.exporters.node.port
}"
];
}];
}
{
job_name = "synapse";
scrape_interval = "15s";
metrics_path = "/_synapse/metrics";
static_configs = [{ targets = [ "10.0.1.1:9000" ]; }];
}
{
job_name = "dmarc";
scrape_interval = "15s";
static_configs = [{
targets = [
"10.0.2.3:${
toString config.services.prometheus.exporters.dmarc.port
}"
];
}];
}
];
};
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
services.loki = {
enable = true;
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
dataDir = "/nix/var/data/loki";
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
configuration = {
server.http_listen_port = 3100;
auth_enabled = false;
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
ingester = {
lifecycler = {
address = "127.0.0.1";
ring = {
kvstore = { store = "inmemory"; };
replication_factor = 1;
2022-09-15 21:42:58 +02:00
};
};
2024-03-26 23:37:53 +01:00
chunk_idle_period = "1h";
max_chunk_age = "1h";
chunk_target_size = 999999;
chunk_retain_period = "30s";
2022-09-15 21:42:58 +02:00
};
limits_config = {
ingestion_rate_mb = 16;
allow_structured_metadata = false;
};
2024-03-26 23:37:53 +01:00
schema_config = {
configs = [{
from = "2022-09-15";
store = "boltdb-shipper";
object_store = "filesystem";
schema = "v11";
index = {
prefix = "index_";
period = "24h";
};
}];
};
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
storage_config = {
boltdb_shipper = {
active_index_directory =
"${config.services.loki.dataDir}/boltdb-index";
cache_location = "${config.services.loki.dataDir}/boltdb-cache";
cache_ttl = "24h";
2022-09-15 21:42:58 +02:00
};
2024-03-26 23:37:53 +01:00
filesystem = {
directory = "${config.services.loki.dataDir}/chunks";
};
2022-09-15 21:42:58 +02:00
};
2024-03-26 23:37:53 +01:00
limits_config = {
reject_old_samples = true;
reject_old_samples_max_age = "168h";
2022-09-15 21:42:58 +02:00
};
querier.engine.max_look_back_period = "0s";
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
table_manager = {
retention_deletes_enabled = false;
retention_period = "0s";
};
2022-09-15 21:42:58 +02:00
2024-03-26 23:37:53 +01:00
compactor = {
working_directory = "${config.services.loki.dataDir}";
compactor_ring = { kvstore = { store = "inmemory"; }; };
2022-09-15 21:42:58 +02:00
};
2024-03-26 23:37:53 +01:00
analytics = { reporting_enabled = false; };
2022-09-15 21:42:58 +02:00
};
};
};
}