Skip to content

Commit

Permalink
promtail: add basic log shipping configuration
Browse files Browse the repository at this point in the history
This automatically enables promtail when a Loki server is present in
the same resource group. Currently only a single Loki server is
supported.

PL-132981
  • Loading branch information
sysvinit committed Sep 11, 2024
1 parent 02975e5 commit 18b49c9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/platform/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ in {
./monitoring.nix
./network.nix
./packages.nix
./promtail.nix
./shell.nix
./static.nix
./syslog.nix
Expand Down
51 changes: 51 additions & 0 deletions nixos/platform/promtail.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{ lib, config, ... }:

let
enc = config.flyingcircus.enc;
fclib = config.fclib;

# XXX support multiple loki servers. the upstream docs note: "It is
# generally recommended to run multiple Promtail clients in parallel
# if you want to send to multiple remote Loki instances."
lokiServer = fclib.findOneService "loki-collector";
in
{
config = lib.mkIf (!builtins.isNull lokiServer) {
services.promtail = {
enable = true;
configuration = {
# don't expose the http and grpc api
server.disable = true;

clients = [{
url = "http://${lokiServer.address}:3100/loki/api/v1/push";
}];

scrape_configs = [{
job_name = "systemd-journal";
journal = {
json = true;
# there are server side limits to how many labels loki
# will accept on log lines. consider them a scarce
# resource and use them sparingly.
labels = {
resource_group = enc.parameters.resource_group;
location = enc.parameters.location;
hostname = config.networking.hostName;
};
};
relabel_configs = [
{
source_labels = [ "__journal__systemd_unit" ];
target_label = "systemd_unit";
}
{
source_labels = [ "__journal_syslog_identifier" ];
target_label = "syslog_identifier";
}
];
}];
};
};
};
}

0 comments on commit 18b49c9

Please sign in to comment.