diff options
Diffstat (limited to '')
| -rw-r--r-- | modules/by-name/mo/monitoring/components/loki.nix | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/modules/by-name/mo/monitoring/components/loki.nix b/modules/by-name/mo/monitoring/components/loki.nix new file mode 100644 index 0000000..9a285c5 --- /dev/null +++ b/modules/by-name/mo/monitoring/components/loki.nix @@ -0,0 +1,122 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.vhack.monitoring.loki; +in { + options.vhack.monitoring.loki = { + enable = lib.mkEnableOption "loki"; + + port = lib.mkOption { + type = lib.types.port; + description = "Port where Loki listens to HTTP requests."; + default = 3002; + }; + }; + + config = lib.mkIf cfg.enable { + services = { + loki = { + enable = true; + dataDir = "/var/lib/loki"; + package = pkgs.grafana-loki; + configuration = { + auth_enabled = false; + + server.http_listen_port = cfg.port; + + common = { + ring = { + instance_addr = "127.0.0.1"; + kvstore = { + store = "inmemory"; + }; + }; + + replication_factor = 1; + path_prefix = "/tmp/loki"; + }; + + schema_config = { + configs = [ + { + from = "2020-05-15"; + store = "tsdb"; + object_store = "filesystem"; + schema = "v13"; + index = { + prefix = "index_"; + period = "24h"; + }; + } + ]; + }; + + storage_config = { + filesystem.directory = "/tmp/loki/chunks"; + }; + }; + }; + + # I decided to switch to fluent-bit because it can be tested locally https://docs.fluentbit.io/manual/local-testing/logging-pipeline + fluent-bit = { + enable = true; + settings = { + service = { + flush = 1; + log_level = "info"; + http_server = "true"; + http_listen = "127.0.0.1"; + http_port = 9080; + grace = 30; + }; + + pipeline = { + inputs = [ + { + name = "systemd"; + + # The asterisk appends the _SYSTEMD_UNIT to the prefix. + tag = "systemd.*"; + + # Read logs from this systemd journal directory. + path = "/var/log/journal"; + + # Database file to keep track of the journald cursor. + db = "/var/fluent-bit/systemd.db"; + + # Start reading new entries. Skip entries already stored in journald. + read_from_tail = true; + + # Max entries to lookback on start. + max_entries = 10000; + } + ]; + + outputs = [ + { + name = "loki"; + + match = "systemd.*"; + + host = "localhost"; + port = config.services.loki.configuration.server.http_listen_port; + + labels = lib.concatMapAttrsStringSep ", " (n: v: "${n}=${v}") { + job = "systemd-journal"; + inherit (config.vhack.monitoring.grafana) fqdn; + hostname = config.networking.hostName; + }; + + label_keys = "$unit"; + } + ]; + }; + }; + graceLimit = "1m"; + }; + }; + }; +} |
