You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
5.4 KiB
181 lines
5.4 KiB
# https://raw.githubusercontent.com/grafana/loki/v2.8.0/production/docker-compose.yaml
|
|
# https://grafana.com/docs/loki/latest/clients/docker-driver/
|
|
|
|
- name: Set up Loki
|
|
hosts: lotus-land-story
|
|
tasks:
|
|
|
|
- name: Provision Grafana
|
|
ansible.builtin.copy:
|
|
dest: /mnt/lotus-land-story/grafana/provisioning/datasources/loki.yml
|
|
content: |
|
|
apiVersion: 1
|
|
|
|
datasources:
|
|
- name: Loki
|
|
type: loki
|
|
access: proxy
|
|
url: http://loki:3100
|
|
mode: "0644"
|
|
|
|
- name: Create Loki config dirs
|
|
ansible.builtin.file:
|
|
path: /mnt/lotus-land-story/loki/{{ item }}
|
|
state: directory
|
|
owner: 10001
|
|
group: 10001
|
|
mode: "0755"
|
|
loop:
|
|
- config
|
|
- data
|
|
|
|
- name: Configure Loki
|
|
ansible.builtin.copy:
|
|
dest: /mnt/lotus-land-story/loki/config/loki.yml
|
|
content: |
|
|
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: boltdb-shipper
|
|
object_store: filesystem
|
|
schema: v11
|
|
index:
|
|
prefix: index_
|
|
period: 24h
|
|
|
|
# https://grafana.com/docs/loki/latest/operations/storage/tsdb/
|
|
- from: 2023-07-17
|
|
index:
|
|
period: 24h
|
|
prefix: index_
|
|
object_store: filesystem
|
|
schema: v12
|
|
store: tsdb
|
|
|
|
storage_config:
|
|
filesystem:
|
|
directory: /data
|
|
ruler:
|
|
alertmanager_url: http://localhost:9093
|
|
owner: 10001
|
|
group: 10001
|
|
mode: "0644"
|
|
|
|
# https://github.com/grafana/loki/issues/2361
|
|
- name: Configure Promtail
|
|
ansible.builtin.copy:
|
|
dest: /mnt/lotus-land-story/loki/config/promtail.yml
|
|
content: |
|
|
server:
|
|
http_listen_port: 9080
|
|
grpc_listen_port: 0
|
|
positions:
|
|
filename: /tmp/positions.yaml
|
|
clients:
|
|
- url: http://loki:3100/loki/api/v1/push
|
|
scrape_configs:
|
|
- job_name: system
|
|
static_configs:
|
|
- targets:
|
|
- localhost
|
|
labels:
|
|
job: varlogs
|
|
__path__: /var/log/*.log
|
|
__path_exclude__: /var/log/syslog
|
|
# - job_name: docker
|
|
# docker_sd_configs:
|
|
# - host: unix:///var/run/docker.sock
|
|
# refresh_interval: 5s
|
|
# relabel_configs:
|
|
# - source_labels: ['__meta_docker_container_name']
|
|
# regex: '/(.*)'
|
|
# target_label: 'container'
|
|
- job_name: syslog
|
|
syslog:
|
|
listen_address: 0.0.0.0:514
|
|
listen_protocol: tcp
|
|
idle_timeout: 60s
|
|
label_structured_data: yes
|
|
labels:
|
|
job: syslog
|
|
relabel_configs:
|
|
- source_labels: ['__syslog_message_hostname']
|
|
target_label: 'host'
|
|
- source_labels: ['__syslog_message_severity']
|
|
target_label: level
|
|
- source_labels: ['__syslog_message_facility']
|
|
target_label: syslog_facility
|
|
- source_labels: ['__syslog_message_app_name']
|
|
target_label: syslog_identifier
|
|
mode: "0644"
|
|
|
|
- name: Run Loki
|
|
community.docker.docker_container:
|
|
name: loki
|
|
image: grafana/loki:2.8.0
|
|
restart: true
|
|
command: -config.file=/mnt/config/loki.yml
|
|
ports:
|
|
- "3100:3100"
|
|
volumes:
|
|
- /mnt/lotus-land-story/loki/config:/mnt/config
|
|
- /mnt/lotus-land-story/loki/data:/data
|
|
restart_policy: unless-stopped
|
|
networks:
|
|
- name: lotus_land_story
|
|
etc_hosts:
|
|
host.docker.internal: host-gateway
|
|
|
|
- name: Run Promtail
|
|
community.docker.docker_container:
|
|
name: promtail
|
|
image: grafana/promtail:2.8.0
|
|
restart: true
|
|
command: -config.file=/mnt/config/promtail.yml
|
|
ports:
|
|
- "514:514"
|
|
volumes:
|
|
- /var/log:/var/log
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
- /mnt/lotus-land-story/loki/config:/mnt/config
|
|
restart_policy: unless-stopped
|
|
networks:
|
|
- name: lotus_land_story
|
|
etc_hosts:
|
|
host.docker.internal: host-gateway
|
|
|
|
- name: Ship to promtail using rsyslog
|
|
ansible.builtin.copy:
|
|
content: |
|
|
*.* action(type="omfwd"
|
|
protocol="tcp"
|
|
target="127.0.0.1"
|
|
port="514"
|
|
Template="RSYSLOG_SyslogProtocol23Format"
|
|
TCP_Framing="octet-counted"
|
|
KeepAlive="on")
|
|
dest: /etc/rsyslog.d/50-promtail.conf
|
|
mode: "0644"
|
|
notify: Restart rsyslog
|
|
|
|
handlers:
|
|
- name: Restart rsyslog
|
|
ansible.builtin.service:
|
|
name: rsyslog
|
|
state: restarted
|
|
|
|
# vim: ft=yaml.ansible
|