-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpromtail.nix
100 lines (98 loc) · 2.35 KB
/
promtail.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ config, lib, pkgs, ... }:
let
prettyJSON = conf:
pkgs.runCommand "promtail-config.json" { } ''
echo '${builtins.toJSON conf}' | ${pkgs.jq}/bin/jq 'del(._module)' > $out
'';
dataDir = "/var/lib/promtail";
syslog = {
job_name = "syslog";
syslog = {
listen_address = "0.0.0.0:514";
idle_timeout = "60s";
label_structured_data = true;
labels = {
job = "syslog";
};
};
relabel_configs = [
{
source_labels = [ "__syslog_message_hostname" ];
target_label = "host";
}
{
source_labels = [ "__syslog_connection_ip_address" ];
target_label = "ip";
}
{
source_labels = ["__syslog_message_app_name"];
target_label = "app";
}
{
source_labels = ["__syslog_message_severity"];
target_label = "level";
}
];
};
journal = {
job_name = "journal";
journal = {
max_age= "12h";
labels = {
job = "systemd-journal";
};
};
relabel_configs = [
{
source_labels = [ "__journal__systemd_unit" ];
target_label = "unit";
}
{
source_labels = [ "__journal__hostname" ];
target_label = "host";
}
{
source_labels = ["__journal_syslog_identifier"];
target_label = "service";
}
{
source_labels = ["__journal_errno"];
target_label = "severity";
}
{
source_labels = ["__journal_priority"];
target_label = "level";
}
{
source_labels = ["__journal__UID"];
target_label = "uid";
}
{
source_labels = ["__journal__GID"];
target_label = "gid";
}
];
};
configuration = {
server = {
http_listen_port = 9080;
grpc_listen_port = 0;
};
clients = [{
url = "http://log.internal:3100/loki/api/v1/push";
}];
scrape_configs = [ syslog ];
};
in {
systemd.services.promtail = {
description = "Promtail Service Daemon";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkgs.grafana-loki}/bin/promtail -config.file=${prettyJSON configuration} -positions.file=${dataDir}/position.yaml";
Restart = "always";
WorkingDirectory = dataDir;
StateDirectory = "promtail";
};
};
networking.firewall.allowedTCPPorts = [ 514 ];
}