loki #23
7 changed files with 140 additions and 0 deletions
Binary file not shown.
|
@ -8,5 +8,7 @@
|
|||
./dns.nix
|
||||
./grafana.nix
|
||||
./prometheus.nix
|
||||
./loki.nix
|
||||
./promtail.nix
|
||||
];
|
||||
}
|
||||
|
|
|
@ -17,6 +17,26 @@ in
|
|||
inherit domain;
|
||||
};
|
||||
};
|
||||
provision = {
|
||||
enable = true;
|
||||
datasources.settings = {
|
||||
datasources =
|
||||
[
|
||||
{
|
||||
name = "Prometheus";
|
||||
type = "prometheus";
|
||||
access = "proxy";
|
||||
url = "http://127.0.0.1:${toString config.services.prometheus.port}";
|
||||
}
|
||||
{
|
||||
name = "Loki";
|
||||
type = "loki";
|
||||
access = "proxy";
|
||||
url = "http://127.0.0.1:${toString config.services.loki.configuration.server.http_listen_port}";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts."${domain}" = {
|
||||
|
|
BIN
hosts/tatos/services/loki-basicauth.age
Normal file
BIN
hosts/tatos/services/loki-basicauth.age
Normal file
Binary file not shown.
85
hosts/tatos/services/loki.nix
Normal file
85
hosts/tatos/services/loki.nix
Normal file
|
@ -0,0 +1,85 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.loki;
|
||||
nginxCfg = config.services.nginx;
|
||||
basePath = "/var/lib/loki";
|
||||
in
|
||||
{
|
||||
age.secrets.loki-basicauth = {
|
||||
file = ./loki-basicauth.age;
|
||||
owner = nginxCfg.user;
|
||||
inherit (nginxCfg) group;
|
||||
};
|
||||
|
||||
services.loki = {
|
||||
enable = true;
|
||||
configuration = {
|
||||
auth_enabled = false;
|
||||
server = {
|
||||
http_listen_address = "127.0.0.1";
|
||||
http_listen_port = 3100;
|
||||
};
|
||||
common = {
|
||||
path_prefix = basePath;
|
||||
};
|
||||
ingester = {
|
||||
lifecycler = {
|
||||
address = "127.0.0.1";
|
||||
ring = {
|
||||
kvstore = {
|
||||
store = "inmemory";
|
||||
};
|
||||
replication_factor = 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
compactor = {
|
||||
working_directory = "${basePath}/compactor";
|
||||
};
|
||||
schema_config = {
|
||||
configs = [
|
||||
{
|
||||
from = "2025-02-04";
|
||||
store = "tsdb";
|
||||
object_store = "filesystem";
|
||||
schema = "v13";
|
||||
index = {
|
||||
prefix = "index_";
|
||||
period = "24h";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
storage_config = {
|
||||
filesystem = {
|
||||
directory = "${basePath}/chunks";
|
||||
};
|
||||
tsdb_shipper = {
|
||||
active_index_directory = "${basePath}/tsdb-index";
|
||||
cache_location = "${basePath}/tsdb-cache";
|
||||
};
|
||||
};
|
||||
|
||||
# Лимиты
|
||||
limits_config = {
|
||||
reject_old_samples = true;
|
||||
reject_old_samples_max_age = "168h"; # Максимальный возраст логов (7 дней)
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = lib.mkIf cfg.enable [
|
||||
"d ${basePath} 0755 ${cfg.user} ${cfg.group} -"
|
||||
];
|
||||
|
||||
services.nginx.virtualHosts."loki.pleshevski.ru" = lib.mkIf cfg.enable {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/" = let inherit (cfg.configuration.server) http_listen_port http_listen_address; in {
|
||||
proxyPass = "http://${http_listen_address}:${toString http_listen_port}";
|
||||
proxyWebsockets = true;
|
||||
basicAuthFile = config.age.secrets.loki-basicauth.path;
|
||||
};
|
||||
};
|
||||
}
|
33
hosts/tatos/services/promtail.nix
Normal file
33
hosts/tatos/services/promtail.nix
Normal file
|
@ -0,0 +1,33 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
services.promtail = {
|
||||
enable = true;
|
||||
configuration = {
|
||||
server = {
|
||||
http_listen_port = 9080;
|
||||
grpc_listen_port = 0;
|
||||
};
|
||||
clients = [
|
||||
{ url = "http://127.0.0.1:3100/loki/api/v1/push"; }
|
||||
];
|
||||
scrape_configs = [
|
||||
{
|
||||
job_name = "journal";
|
||||
journal = {
|
||||
labels = {
|
||||
job = "systemd-journal";
|
||||
host = "${config.networking.hostName}"; # Имя хоста как метка
|
||||
};
|
||||
};
|
||||
relabel_configs = [
|
||||
{
|
||||
source_labels = [ "__journal__systemd_unit" ];
|
||||
target_label = "unit";
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
Binary file not shown.
Loading…
Add table
Reference in a new issue