nix/nixos/common/services/promtail.nix

51 lines
1.2 KiB
Nix
Raw Normal View History

2023-07-05 13:39:53 +09:00
{ config, pkgs, hostname, ... }: {
2023-06-30 11:39:01 +09:00
# Promtail Logging
2023-07-05 10:05:02 +09:00
2023-07-12 23:41:12 +09:00
# Set up the secret for the password:
2023-07-05 10:37:48 +09:00
sops.secrets.promtail-pass = {
2023-07-05 10:05:02 +09:00
owner = "promtail";
2023-08-23 17:21:11 +09:00
sopsFile = ../../../secrets/secrets.yaml;
2023-07-05 13:20:49 +09:00
restartUnits = [ "promtail.service" ];
};
2023-06-30 11:39:01 +09:00
# Install the package
environment.systemPackages = with pkgs; [
promtail
];
# Configure the package:
# https://mynixos.com/nixpkgs/option/services.promtail.configuration
services.promtail = {
enable = true;
configuration = {
2023-06-30 17:59:07 +09:00
server = {
http_listen_port = 3031;
grpc_listen_port = 0;
};
positions = {
filename = "/tmp/positions.yaml";
};
clients = [{
2023-07-05 10:29:56 +09:00
url = "https://loki.sysctl.io/loki/api/v1/push";
2023-06-30 17:59:07 +09:00
basic_auth = {
2023-07-05 10:05:02 +09:00
username = "loki-sa";
2023-07-05 10:36:38 +09:00
password_file = config.sops.secrets.promtail-pass.path;
2023-06-30 18:00:20 +09:00
};
}];
2023-06-30 17:59:07 +09:00
scrape_configs = [{
job_name = "journal";
journal = {
max_age = "12h";
labels = {
job = "systemd-journal";
2023-07-05 13:39:53 +09:00
host = "${hostname}";
2023-06-30 17:59:07 +09:00
};
};
relabel_configs = [{
source_labels = [ "__journal__systemd_unit" ];
target_label = "unit";
2023-06-30 18:00:20 +09:00
}];
}];
2023-06-30 11:39:01 +09:00
};
};
}