From 88c718eb772d7435a4ece81e531bf3f2bbb8a5fa Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Sat, 27 Dec 2025 21:20:31 -0500 Subject: [PATCH] add loki + promtail --- tasks/monitoring.yml | 50 ++++++++++++++++++++++++--- templates/monitoring/loki.yaml.j2 | 29 ++++++++++++++++ templates/monitoring/promtail.yaml.j2 | 17 +++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 templates/monitoring/loki.yaml.j2 create mode 100644 templates/monitoring/promtail.yaml.j2 diff --git a/tasks/monitoring.yml b/tasks/monitoring.yml index eff1886..fd14b4d 100644 --- a/tasks/monitoring.yml +++ b/tasks/monitoring.yml @@ -3,7 +3,7 @@ include_role: name: docker vars: - name: prometheus + name: monitoring_prometheus network_name: "monitoring" networks: - name: "monitoring" @@ -11,6 +11,8 @@ directories: - "{{ data_dir }}/monitoring" - "{{ data_dir }}/monitoring/grafana" + - "{{ data_dir }}/monitoring/loki" + - "{{ data_dir }}/monitoring/promtail" - "{{ data_dir }}/monitoring/prometheus" image: name: prom/prometheus @@ -25,11 +27,21 @@ traefik.http.routers.prom.tls.certresolver: letsencrypt traefik.http.services.prom.loadbalancer.server.port: "9090" +# copy configs for loki + promtail +- name: Create Loki Configuration + template: + src: templates/monitoring/loki.yaml.j2 + dest: "{{ data_dir }}/monitoring/loki/loki-config.yaml" +- name: Create Promtail Configuration + template: + src: templates/monitoring/promtail.yaml.j2 + dest: "{{ data_dir }}/monitoring/promtail/promtail-config.yaml" + - name: Deploy Node Exporter include_role: name: docker vars: - name: node-exporter + name: monitoring_node-exporter image: name: prom/node-exporter tag: latest @@ -44,7 +56,7 @@ include_role: name: docker vars: - name: cadvisor + name: monitoring_cadvisor image: name: ghcr.io/google/cadvisor tag: 0.55.1 @@ -60,11 +72,41 @@ devices: - /dev/kmsg +- name: Deploy Loki + include_role: + name: docker + vars: + name: monitoring_loki + volume_name: grafana-loki + image: + name: grafana/loki + tag: latest + volumes: + - "{{ data_dir }}/monitoring/loki/loki-config.yaml:/etc/loki/local-config.yaml" + - "grafana-loki:/loki" + networks: + - name: "monitoring" + +- name: Deploy Promtail + include_role: + name: docker + vars: + name: monitoring_promtail + image: + name: grafana/promtail + tag: latest + command: -config.file=/etc/promtail/config.yaml + networks: + - name: "monitoring" + volumes: + - "/var/log:/var/log:ro" + - "{{ data_dir }}/monitoring/promtail/promtail-config.yaml:/etc/promtail/config.yaml" + - name: Deploy Grafana include_role: name: docker vars: - name: grafana + name: monitoring_grafana volume_name: "grafana-storage" networks: - name: "monitoring" diff --git a/templates/monitoring/loki.yaml.j2 b/templates/monitoring/loki.yaml.j2 new file mode 100644 index 0000000..aa14017 --- /dev/null +++ b/templates/monitoring/loki.yaml.j2 @@ -0,0 +1,29 @@ +auth_enabled: false + +server: + http_listen_port: 3100 + +common: + path_prefix: /loki + storage: + filesystem: + chunks_directory: /loki/chunks + rules_directory: /loki/rules + replication_factor: 1 + ring: + kvstore: + store: inmemory + +schema_config: + configs: + - from: 2020-10-24 + store: tsdb + object_store: filesystem + schema: v13 + index: + prefix: index_ + period: 24h + +storage_config: + filesystem: + directory: /loki/chunks diff --git a/templates/monitoring/promtail.yaml.j2 b/templates/monitoring/promtail.yaml.j2 new file mode 100644 index 0000000..601fe75 --- /dev/null +++ b/templates/monitoring/promtail.yaml.j2 @@ -0,0 +1,17 @@ +server: + http_listen_port: 9080 + +positions: + filename: /tmp/positions.yaml + +clients: + - url: http://monitoring_loki:3100/loki/api/v1/push + +scrape_configs: + - job_name: system + static_configs: + - targets: + - localhost + labels: + job: varlogs + __path__: /var/log/**/*.log