94 lines
2.3 KiB
Nix
94 lines
2.3 KiB
Nix
{config, ...}: let
|
|
inherit (config.services) loki;
|
|
in {
|
|
services.loki = {
|
|
enable = true;
|
|
configuration = {
|
|
auth_enabled = false;
|
|
server.http_listen_port = 3100;
|
|
schema_config.configs = [
|
|
{
|
|
from = "2024-10-12";
|
|
object_store = "filesystem";
|
|
store = "tsdb";
|
|
schema = "v13";
|
|
index = {
|
|
prefix = "index_";
|
|
period = "24h";
|
|
};
|
|
}
|
|
];
|
|
storage_config."filesystem".directory = "/tmp/loki/chunks";
|
|
common = {
|
|
ring = {
|
|
kvstore.store = "inmemory";
|
|
};
|
|
replication_factor = 1;
|
|
path_prefix = "/tmp/loki";
|
|
};
|
|
# https://grafana.com/docs/loki/latest/configure/#limits_config
|
|
limits_config = {
|
|
ingestion_rate_strategy = "local";
|
|
ingestion_rate_mb = 128;
|
|
ingestion_burst_size_mb = 256;
|
|
max_streams_per_user = 0;
|
|
max_global_streams_per_user = 0;
|
|
};
|
|
};
|
|
};
|
|
services.prometheus.scrapeConfigs = [
|
|
{
|
|
job_name = "loki";
|
|
static_configs = [
|
|
{
|
|
targets = ["localhost:3100"];
|
|
}
|
|
];
|
|
}
|
|
];
|
|
services.alloy = {
|
|
enable = true;
|
|
};
|
|
environment.etc."alloy/config.alloy" = {
|
|
text = ''
|
|
discovery.relabel "system" {
|
|
targets = []
|
|
|
|
rule {
|
|
source_labels = ["__journal__systemd_unit", "__journal__systemd_user_unit"]
|
|
regex = "(.+)"
|
|
target_label = "systemd_unit"
|
|
}
|
|
|
|
rule {
|
|
source_labels = ["__journal__priority_keyword"]
|
|
regex = "(.+)"
|
|
target_label = "severity"
|
|
}
|
|
}
|
|
|
|
loki.source.journal "system" {
|
|
max_age = "1h0m0s"
|
|
path = "/var/log/journal/"
|
|
relabel_rules = discovery.relabel.system.rules
|
|
forward_to = [loki.write.default.receiver]
|
|
labels = {}
|
|
}
|
|
|
|
loki.write "default" {
|
|
endpoint {
|
|
url = "http://localhost:3100/loki/api/v1/push"
|
|
}
|
|
max_streams = 24
|
|
}
|
|
|
|
'';
|
|
};
|
|
services.grafana.provision.datasources.settings.datasources = [
|
|
{
|
|
name = "Loki";
|
|
type = "loki";
|
|
url = "http://localhost:${toString loki.configuration.server.http_listen_port}";
|
|
}
|
|
];
|
|
}
|