2024-08-29 11:51:08 +07:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.profile.services.telemetry.loki;
|
|
|
|
inherit (lib) mkIf;
|
2024-10-30 16:23:03 +07:00
|
|
|
inherit (lib.lists) optional;
|
2024-08-29 13:19:48 +07:00
|
|
|
lokiDomain = "loki.tigor.web.id";
|
2024-09-02 18:17:03 +07:00
|
|
|
server = config.services.loki.configuration.server;
|
2024-08-29 11:51:08 +07:00
|
|
|
in
|
|
|
|
{
|
|
|
|
config = mkIf cfg.enable {
|
2024-10-21 12:31:30 +07:00
|
|
|
services.caddy.virtualHosts.${lokiDomain}.extraConfig = # caddy
|
|
|
|
''
|
2024-10-28 21:38:34 +07:00
|
|
|
basic_auth {
|
|
|
|
{$AUTH_USERNAME} {$AUTH_PASSWORD}
|
2024-10-21 12:31:30 +07:00
|
|
|
}
|
|
|
|
reverse_proxy ${server.http_listen_address}:${toString server.http_listen_port}
|
|
|
|
'';
|
2024-08-29 13:19:48 +07:00
|
|
|
|
2024-08-29 11:51:08 +07:00
|
|
|
services.loki =
|
|
|
|
let
|
|
|
|
dataDir = config.services.loki.dataDir;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
configuration = {
|
|
|
|
# https://grafana.com/docs/loki/latest/configure/examples/configuration-examples/
|
2024-08-29 13:19:48 +07:00
|
|
|
auth_enabled = false;
|
2024-08-29 11:51:08 +07:00
|
|
|
server = {
|
|
|
|
http_listen_address = "0.0.0.0";
|
|
|
|
http_listen_port = 3100;
|
|
|
|
grpc_listen_port = 9095;
|
|
|
|
};
|
|
|
|
|
|
|
|
common = {
|
|
|
|
path_prefix = dataDir;
|
|
|
|
replication_factor = 1;
|
|
|
|
ring = {
|
|
|
|
instance_addr = "127.0.0.1";
|
|
|
|
kvstore.store = "inmemory";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
schema_config = {
|
|
|
|
configs = [
|
|
|
|
{
|
|
|
|
from = "2024-08-29";
|
|
|
|
store = "tsdb";
|
|
|
|
object_store = "filesystem";
|
|
|
|
schema = "v13";
|
|
|
|
index = {
|
|
|
|
prefix = "index_";
|
|
|
|
period = "24h";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-09-12 11:47:15 +07:00
|
|
|
ruler = {
|
|
|
|
external_url = "https://grafana.tigor.web.id";
|
|
|
|
storage = {
|
|
|
|
type = "local";
|
|
|
|
local = {
|
|
|
|
directory = "${dataDir}/rules";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
rule_path = "/tmp/loki/rules"; # Temporary rule_path
|
|
|
|
};
|
|
|
|
|
2024-09-11 21:50:22 +07:00
|
|
|
compactor = {
|
|
|
|
working_directory = "${dataDir}/retention";
|
|
|
|
retention_enabled = true;
|
|
|
|
delete_request_store = "filesystem";
|
|
|
|
};
|
|
|
|
|
|
|
|
limits_config = {
|
|
|
|
retention_period = "90d";
|
2024-09-16 10:32:43 +07:00
|
|
|
ingestion_burst_size_mb = 64;
|
|
|
|
ingestion_rate_mb = 32;
|
2024-09-11 21:50:22 +07:00
|
|
|
};
|
|
|
|
|
2024-08-29 11:51:08 +07:00
|
|
|
storage_config = {
|
|
|
|
filesystem = {
|
|
|
|
directory = "${dataDir}/chunks";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# https://grafana.com/docs/grafana/latest/datasources/loki/
|
|
|
|
services.grafana.provision.datasources.settings.datasources = [
|
|
|
|
{
|
|
|
|
name = "Loki";
|
|
|
|
type = "loki";
|
2024-09-02 18:17:03 +07:00
|
|
|
uid = "loki";
|
2024-08-29 11:51:08 +07:00
|
|
|
access = "proxy";
|
2024-09-02 18:17:03 +07:00
|
|
|
url = "http://${server.http_listen_address}:${toString server.http_listen_port}";
|
|
|
|
basicAuth = false;
|
2024-08-29 11:51:08 +07:00
|
|
|
jsonData = {
|
|
|
|
timeout = 60;
|
|
|
|
maxLines = 1000;
|
2024-10-30 16:23:03 +07:00
|
|
|
derivedFields =
|
|
|
|
[ ]
|
|
|
|
++ (optional config.services.tempo.enable {
|
|
|
|
datasourceUid = "tempo";
|
2024-10-30 16:30:27 +07:00
|
|
|
matcherRegex = ''trace_?[Ii][Dd]=(\w+)'';
|
|
|
|
name = "Log Trace";
|
2024-10-30 16:23:03 +07:00
|
|
|
url = "$\${__value.raw}";
|
|
|
|
urlDisplayLabel = "Trace";
|
|
|
|
})
|
|
|
|
++ (optional config.services.tempo.enable {
|
|
|
|
datasourceUid = "tempo";
|
2024-10-30 16:30:27 +07:00
|
|
|
matcherRegex = ''"trace_?[Ii][Dd]":"(\w+)"'';
|
|
|
|
name = "Trace";
|
2024-10-30 16:23:03 +07:00
|
|
|
url = "$\${__value.raw}";
|
|
|
|
urlDisplayLabel = "Trace";
|
|
|
|
});
|
2024-08-29 11:51:08 +07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|