add promtail log shipping

This commit is contained in:
Ingolf Wagner 2024-05-15 14:39:21 +02:00
commit e69fdc44d9
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
7 changed files with 101 additions and 16 deletions

View file

@ -14,6 +14,7 @@ with types;
./netdata.nix
./opentelemetry.nix
./prometheus.nix
./promtail.nix
./telegraf.nix
];

View file

@ -62,9 +62,9 @@ in
pipelines.metrics = {
exporters = [ "otlp" ];
};
#pipelines.logs = {
# exporters = [ "otlp" ];
#};
pipelines.logs = {
exporters = [ "otlp" ];
};
};
};
})
@ -77,9 +77,9 @@ in
pipelines.metrics = {
receivers = [ "otlp" ];
};
#pipelines.logs = {
# exporters = [ "otlp" ];
#};
pipelines.logs = {
receivers = [ "otlp" ];
};
};
};
})

View file

@ -0,0 +1,67 @@
{ config, lib, ... }:
with lib;
with types;
let
cfg = config.components.monitor.promtail;
in
{
options.components.monitor.promtail = {
enable = mkOption {
type = lib.types.bool;
default = config.components.monitor.enable;
};
port = mkOption {
type = int;
default = 3500;
description = "port to provide promtail export";
};
};
config = mkMerge [
(mkIf config.components.monitor.promtail.enable {
services.opentelemetry-collector.settings = {
receivers.loki = {
protocols.http.endpoint = "127.0.0.1:${toString cfg.port}";
use_incoming_timestamp = true;
};
service.pipelines.logs.receivers = [ "loki" ];
};
services.promtail = {
enable = true;
configuration = {
server = {
http_listen_port = 28183;
grpc_listen_port = 0;
};
positions.filename = "/tmp/positions.yaml";
clients = [
{ url = "http://127.0.0.1:${toString cfg.port}/loki/api/v1/push"; }
];
scrape_configs = [
{
job_name = "journal";
journal = {
max_age = "12h";
};
relabel_configs = [
{
source_labels = [ "__journal__systemd_unit" ];
target_label = "unit";
}
{
source_labels = [ "__journal__transport" ];
target_label = "transport";
}
];
}
];
};
};
})
];
}