nix/modules/monitoring/loki.nix
2024-10-07 22:03:55 +02:00

94 lines
2.1 KiB
Nix

{
lib,
config,
pkgs,
...
}:
with lib;
let
cfg = config.my.monitoring.loki;
in
{
options.my.monitoring.loki = {
enable = mkEnableOption "Enable Loki log aggregation module";
};
config = mkIf cfg.enable {
services.loki = {
enable = true;
configuration = {
auth_enabled = false;
server.http_listen_port = 3100;
server.log_level = "warn";
common = {
ring = {
instance_addr = "127.0.0.1";
kvstore.store = "inmemory";
};
replication_factor = 1;
path_prefix = config.services.loki.dataDir;
};
schema_config = {
configs = [
{
from = "2024-07-01";
store = "tsdb";
object_store = "filesystem";
schema = "v13";
index = {
prefix = "index_";
period = "24h";
};
}
];
};
storage_config = {
filesystem.directory = "${config.services.loki.dataDir}/chunks";
tsdb_shipper.active_index_directory = "${config.services.loki.dataDir}/tsdb-index";
tsdb_shipper.cache_location = "${config.services.loki.dataDir}/tsdb-cache";
};
limits_config = {
reject_old_samples = true;
reject_old_samples_max_age = "168h";
};
ruler = {
storage = {
type = "local";
local.directory = "/tmp/rules";
};
rule_path = "/tmp/scratch";
alertmanager_url = "http://nuc:9093";
ring.kvstore.store = "inmemory";
enable_api = true;
};
query_scheduler = {
max_outstanding_requests_per_tenant = 2048;
};
};
};
services.grafana = {
provision.datasources.settings = {
datasources = [
{
name = "Loki localhost";
url = "http://localhost:3100";
type = "loki";
}
];
};
};
networking.firewall.allowedTCPPorts = [ 3100 ];
};
}