]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - systems/zoldene/logging.nix
Use new synapse host
[perso/Immae/Config/Nix.git] / systems / zoldene / logging.nix
CommitLineData
1a64deeb
IB
1{ config, pkgs, name, ... }:
2# Initialization
3# CREATE INDEX ON LOGS (tag);
4# CREATE INDEX ON LOGS (time);
5# CREATE INDEX ON LOGS (((data->>'PRIORITY')::int));
6# CREATE INDEX ON LOGS ((data->>'_SYSTEMD_UNIT'));
7# CREATE INDEX ON LOGS ((data->>'SYSLOG_IDENTIFIER'));
8let
9 fluent-bit-config = {
10 pipeline = {
11 inputs = [
12 {
13 name = "systemd";
14 tag = "${name}.systemd";
15 DB = "/var/lib/fluentbit/fluent-bit.db";
16 }
17 ];
18 outputs = [
19 {
20 name = "loki";
21 match = "${name}.systemd";
22 line_format = "json";
23 labels = "job=fluentbit, server=${name}, priority=$PRIORITY, syslog_identifier=$SYSLOG_IDENTIFIER, systemd_unit=$_SYSTEMD_UNIT";
24 }
25 {
26 name = "pgsql";
27 match = "*";
28 host = "/run/postgresql";
29 user = "fluentbit";
30 table = "logs";
31 database = "fluentbit";
32 timestamp_key = "event_timestamp";
33 }
34 ];
35 };
36 };
37 yamlFormat = pkgs.formats.yaml {};
0efc98bb 38 psqlVersion = pkgs.postgresql_16.psqlSchema;
1a64deeb
IB
39in
40{
41 disko.devices.zpool.zfast.datasets."root/persist/var/lib/loki" =
42 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/loki"; options.mountpoint = "legacy"; };
43 disko.devices.zpool.zfast.datasets."root/persist/var/lib/fluentbit" =
44 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/fluentbit"; options.mountpoint = "legacy"; };
45 disko.devices.zpool.zfast.datasets."root/persist/var/lib/postgresql" =
46 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/postgresql"; options.mountpoint = "legacy"; };
47 disko.devices.zpool.zfast.datasets."root/persist/var/lib/postgresql/${psqlVersion}" =
48 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/postgresql/${psqlVersion}"; options.mountpoint = "legacy"; };
49 environment.persistence."/persist/zfast".directories = [
50 {
51 directory = "/var/lib/postgresql";
52 user = config.users.users.postgres.name;
53 group = config.users.users.postgres.group;
54 mode = "0755";
55 }
d1527470
IB
56 {
57 directory = "/var/lib/postgresql/${psqlVersion}";
58 user = config.users.users.postgres.name;
59 group = config.users.users.postgres.group;
60 mode = "0755";
61 }
1a64deeb
IB
62 {
63 directory = "/var/lib/fluentbit";
64 user = config.users.users.fluentbit.name;
65 group = config.users.users.fluentbit.group;
66 mode = "0755";
67 }
68 {
69 directory = "/var/lib/loki";
70 user = config.users.users.loki.name;
71 group = config.users.users.loki.group;
72 mode = "0755";
73 }
74 ];
75
76 ids.uids.fluentbit = 500;
77 ids.gids.fluentbit = 500;
78 users.users.fluentbit = {
79 name = "fluentbit";
80 home = "/var/lib/fluentbit";
81 uid = config.ids.uids.fluentbit;
82 group = "fluentbit";
83 isSystemUser = true;
84 extraGroups = [ "systemd-journal" ];
85 };
86 users.groups.fluentbit.gid = config.ids.gids.fluentbit;
87
88 services.loki = {
89 enable = true;
90 configuration = {
91 auth_enabled = false;
92 common = {
93 ring.kvstore.store = "inmemory";
94 ring.instance_addr = "127.0.0.1";
95 replication_factor = 1;
96 path_prefix = "/var/lib/loki";
97 };
98 server.log_level = "warn";
99 limits_config = {
100 reject_old_samples = false;
101 ingestion_rate_mb = 100;
102 ingestion_burst_size_mb = 200;
103 per_stream_rate_limit = "100MB";
104 per_stream_rate_limit_burst = "200MB";
105 };
106
107 schema_config.configs = [
108 {
109 from = "2020-10-24";
110 store = "boltdb-shipper";
111 object_store = "filesystem";
112 schema = "v11";
113 index.prefix = "index_";
114 index.period = "24h";
115 }
116 ];
117 };
118 };
d1527470
IB
119 systemd.services.postgresql.after = [
120 "var-lib-postgresql.mount"
121 "var-lib-postgresql-16.mount"
122 "persist-zfast-var-lib-postgresql.mount"
123 "persist-zfast-var-lib-postgresql-16.mount"
124 ];
125 systemd.services.postgresql.unitConfig = {
126 BindsTo = [
127 "var-lib-postgresql.mount"
128 "var-lib-postgresql-16.mount"
129 "persist-zfast-var-lib-postgresql.mount"
130 "persist-zfast-var-lib-postgresql-16.mount"
131 ];
132 };
133
1a64deeb
IB
134 services.postgresql = {
135 enable = true;
0efc98bb 136 package = pkgs.postgresql_16;
1a64deeb
IB
137 ensureDatabases = [ "fluentbit" ];
138 ensureUsers = [
139 {
140 name = "fluentbit";
5707d696 141 ensureDBOwnership = true;
1a64deeb
IB
142 }
143 ];
144 };
145
146 environment.systemPackages = [
147 pkgs.fluent-bit
148 ];
149 systemd.services.fluent-bit = {
150 description = "Fluent-bit daemon";
151 wantedBy = [ "multi-user.target" ];
152 serviceConfig = {
153 ExecStart = "${pkgs.fluent-bit}/bin/fluent-bit -c ${yamlFormat.generate "fluent.yaml" fluent-bit-config}";
154 User = "fluentbit";
155 Group = "fluentbit";
156 SupplementaryGroups = [ "systemd-journal" ];
157 };
158 };
159}