From ffe450cd308b73543ae66e247db8ca07eb998f95 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 13 Feb 2024 19:35:08 -0600 Subject: [PATCH] loki: Run Grafana Loki in a container Deploying Loki is pretty straightforward. It just needs a container unit file and a basic YAML configuration file. --- app/loki/templates.cue | 26 +++++++++++++++++ instructions/loki0.pyrocufflink.blue.cue | 2 ++ templates/loki/config.yml | 37 ++++++++++++++++++++++++ templates/loki/loki.container | 18 ++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 app/loki/templates.cue create mode 100644 templates/loki/config.yml create mode 100644 templates/loki/loki.container diff --git a/app/loki/templates.cue b/app/loki/templates.cue new file mode 100644 index 0000000..a202eaf --- /dev/null +++ b/app/loki/templates.cue @@ -0,0 +1,26 @@ +package loki + +import "du5t1n.me/cfg/base/schema/instructions" + +templates: [...instructions.#RenderInstruction] & [ + { + template: "loki/config.yml" + dest: "/etc/loki/config.yml" + hooks: { + changed: [{run: "systemctl try-restart loki"}] + } + }, + { + template: "loki/loki.container" + dest: "/etc/containers/systemd/loki.container" + hooks: { + changed: [ + { + run: "systemctl daemon-reload" + immediate: true + }, + {run: "systemctl restart loki"}, + ] + } + }, +] diff --git a/instructions/loki0.pyrocufflink.blue.cue b/instructions/loki0.pyrocufflink.blue.cue index 6348fac..165c035 100644 --- a/instructions/loki0.pyrocufflink.blue.cue +++ b/instructions/loki0.pyrocufflink.blue.cue @@ -2,10 +2,12 @@ import ( "list" "du5t1n.me/cfg/app/collectd" + "du5t1n.me/cfg/app/loki" "du5t1n.me/cfg/env/prod" ) render: list.Concat([ collectd.templates, + loki.templates, prod.templates, ]) diff --git a/templates/loki/config.yml b/templates/loki/config.yml new file mode 100644 index 0000000..b11f2f0 --- /dev/null +++ b/templates/loki/config.yml @@ -0,0 +1,37 @@ +auth_enabled: false + +server: + http_listen_port: 3100 + grpc_listen_port: 9096 + +common: + instance_addr: 127.0.0.1 + path_prefix: /var/lib/loki + storage: + filesystem: + chunks_directory: /var/lib/loki/chunks + rules_directory: /var/lib/loki/rules + replication_factor: 1 + ring: + kvstore: + store: inmemory + +query_range: + results_cache: + cache: + embedded_cache: + enabled: true + max_size_mb: 100 + +schema_config: + configs: + - from: 2020-10-24 + store: tsdb + object_store: filesystem + schema: v12 + index: + prefix: index_ + period: 24h + +query_scheduler: + max_outstanding_requests_per_tenant: 1024 diff --git a/templates/loki/loki.container b/templates/loki/loki.container new file mode 100644 index 0000000..e3f31e9 --- /dev/null +++ b/templates/loki/loki.container @@ -0,0 +1,18 @@ +# vim: set ft=systemd : +[Unit] +Description=Grafana Loki +After=network-online.target +Wants=network-online.target + +[Service] +StateDirectory=%P + +[Container] +Image=docker.io/grafana/loki:2.9.4 +Exec=-config.file=/etc/loki/config.yml +Volume=%S/%P:/var/lib/loki:rw,Z,U +Volume=/etc/loki:/etc/loki:ro +PublishPort=3100:3100 + +[Install] +WantedBy=multi-user.target