Update 5 files
- /roles/promtail/tasks/main.yml - /roles/promtail/templates/promtail-config.yml.j2 - /roles/promtail/templates/promtail-service.yml.j2 - /roles/promtail/handlers/main.yml - /group_vars/all.yml
This commit is contained in:
parent
725f286c41
commit
537015263f
@ -259,6 +259,6 @@ loki_base_dir: "/mnt/loki"
|
|||||||
loki_config_dir: "{{ loki_base_dir }}/config"
|
loki_config_dir: "{{ loki_base_dir }}/config"
|
||||||
loki_data_dir: "{{ loki_base_dir }}/data"
|
loki_data_dir: "{{ loki_base_dir }}/data"
|
||||||
promtail_config_dir: "{{ loki_base_dir }}/promtail"
|
promtail_config_dir: "{{ loki_base_dir }}/promtail"
|
||||||
loki_port: 45135
|
loki_port: 3100
|
||||||
loki_version: "2.9.2"
|
loki_version: "2.9.2"
|
||||||
loki_retention_days: 30
|
loki_retention_days: 30
|
||||||
|
|||||||
7
roles/promtail/handlers/main.yml
Normal file
7
roles/promtail/handlers/main.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: restart promtail
|
||||||
|
systemd:
|
||||||
|
name: promtail
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: yes
|
||||||
|
become: yes
|
||||||
66
roles/promtail/tasks/main.yml
Normal file
66
roles/promtail/tasks/main.yml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
---
|
||||||
|
- name: Create Promtail directories
|
||||||
|
file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
loop:
|
||||||
|
- "{{ promtail_config_dir }}"
|
||||||
|
- "{{ promtail_data_dir }}"
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Download Promtail binary
|
||||||
|
get_url:
|
||||||
|
url: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/promtail-linux-amd64.zip"
|
||||||
|
dest: /tmp/promtail-linux-amd64.zip
|
||||||
|
mode: '0644'
|
||||||
|
timeout: 60
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Unzip Promtail binary
|
||||||
|
unarchive:
|
||||||
|
src: /tmp/promtail-linux-amd64.zip
|
||||||
|
dest: /usr/local/bin/
|
||||||
|
remote_src: yes
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0755'
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Create Promtail system user
|
||||||
|
user:
|
||||||
|
name: promtail
|
||||||
|
system: yes
|
||||||
|
shell: /usr/sbin/nologin
|
||||||
|
create_home: no
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Deploy Promtail configuration
|
||||||
|
template:
|
||||||
|
src: promtail-config.yml.j2
|
||||||
|
dest: "{{ promtail_config_dir }}/promtail-config.yml"
|
||||||
|
mode: '0644'
|
||||||
|
notify: restart promtail
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Deploy Promtail systemd service
|
||||||
|
template:
|
||||||
|
src: promtail-service.yml.j2
|
||||||
|
dest: /etc/systemd/system/promtail.service
|
||||||
|
mode: '0644'
|
||||||
|
notify: restart promtail
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Start and enable Promtail service
|
||||||
|
systemd:
|
||||||
|
name: promtail
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: yes
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Clean up temporary files
|
||||||
|
file:
|
||||||
|
path: /tmp/promtail-linux-amd64.zip
|
||||||
|
state: absent
|
||||||
|
become: yes
|
||||||
69
roles/promtail/templates/promtail-config.yml.j2
Normal file
69
roles/promtail/templates/promtail-config.yml.j2
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
server:
|
||||||
|
http_listen_port: 9080
|
||||||
|
grpc_listen_port: 0
|
||||||
|
|
||||||
|
positions:
|
||||||
|
filename: /var/lib/promtail/positions.yaml
|
||||||
|
|
||||||
|
clients:
|
||||||
|
- url: http://{{ loki_server_host }}:{{ loki_server_port }}/loki/api/v1/push
|
||||||
|
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: system
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: system-logs
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
__path__: /var/log/*log
|
||||||
|
|
||||||
|
- job_name: auth
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: auth
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
__path__: /var/log/auth.log
|
||||||
|
|
||||||
|
- job_name: syslog
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: syslog
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
__path__: /var/log/syslog
|
||||||
|
|
||||||
|
- job_name: kernel
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: kernel
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
__path__: /var/log/kern.log
|
||||||
|
|
||||||
|
- job_name: docker
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: container-logs
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
__path__: /var/lib/docker/containers/*/*log
|
||||||
|
relabel_configs:
|
||||||
|
- source_labels: ['__path__']
|
||||||
|
target_label: container_name
|
||||||
|
regex: '/var/lib/docker/containers/([^/]*)/.*log'
|
||||||
|
replacement: '$1'
|
||||||
|
|
||||||
|
- job_name: applications
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: applications
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
__path__: /var/log/*.log
|
||||||
19
roles/promtail/templates/promtail-service.yml.j2
Normal file
19
roles/promtail/templates/promtail-service.yml.j2
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Promtail log collector
|
||||||
|
Documentation=https://grafana.com/docs/loki/latest/clients/promtail/
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=promtail
|
||||||
|
Group=promtail
|
||||||
|
ExecStart=/usr/local/bin/promtail-linux-amd64 \
|
||||||
|
-config.file={{ promtail_config_dir }}/promtail-config.yml
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
KillMode=process
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
Loading…
Reference in New Issue
Block a user