Update 4 files
- /roles/grafana/templates/victoriametrics-datasource.yml.j2 - /roles/grafana/templates/docker-compose.yml.j2 - /roles/grafana/tasks/main.yml - /roles/grafana/handlers/main.yml
This commit is contained in:
parent
8f44c2e4b0
commit
5dffc79a01
@ -5,3 +5,9 @@
|
|||||||
state: restarted
|
state: restarted
|
||||||
services: vmagent
|
services: vmagent
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
|
- name: restart grafana stack
|
||||||
|
community.docker.docker_compose_v2:
|
||||||
|
project_src: "{{ grafana_base_dir }}"
|
||||||
|
state: restarted
|
||||||
|
become: yes
|
||||||
@ -9,9 +9,18 @@
|
|||||||
loop:
|
loop:
|
||||||
- "{{ grafana_base_dir }}"
|
- "{{ grafana_base_dir }}"
|
||||||
- "{{ grafana_data_dir }}"
|
- "{{ grafana_data_dir }}"
|
||||||
- "{{ grafana_config_dir }}"
|
- "{{ grafana_config_dir }}/provisioning/datasources"
|
||||||
|
- "{{ grafana_config_dir }}/provisioning/dashboards"
|
||||||
- "{{ grafana_vm_data_dir }}"
|
- "{{ grafana_vm_data_dir }}"
|
||||||
- "{{ grafana_vmagent_tmp_dir | dirname }}" # создаёт /mnt/grafana/vmagent
|
- "{{ grafana_vmagent_tmp_dir | dirname }}"
|
||||||
|
|
||||||
|
- name: Set proper permissions for Grafana data directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ grafana_data_dir }}"
|
||||||
|
owner: 472
|
||||||
|
group: 472
|
||||||
|
recurse: yes
|
||||||
|
mode: '0755'
|
||||||
|
|
||||||
- name: Deploy vmagent configuration
|
- name: Deploy vmagent configuration
|
||||||
template:
|
template:
|
||||||
@ -31,42 +40,59 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
|
||||||
|
- name: Deploy VictoriaMetrics datasource configuration
|
||||||
|
template:
|
||||||
|
src: victoriametrics-datasource.yml.j2
|
||||||
|
dest: "{{ grafana_config_dir }}/provisioning/datasources/victoriametrics.yml"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- name: Deploy Loki datasource configuration
|
||||||
|
template:
|
||||||
|
src: loki-datasource.yml.j2
|
||||||
|
dest: "{{ grafana_config_dir }}/provisioning/datasources/loki.yml"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
become: yes
|
||||||
|
|
||||||
- name: Start Grafana services
|
- name: Start Grafana services
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cd "{{ grafana_base_dir }}"
|
cd "{{ grafana_base_dir }}"
|
||||||
|
docker compose down
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
args:
|
args:
|
||||||
executable: /bin/bash
|
executable: /bin/bash
|
||||||
register: grafana_up
|
register: grafana_up
|
||||||
changed_when: "'Started' in grafana_up.stdout or 'Recreated' in grafana_up.stdout"
|
changed_when: "'Started' in grafana_up.stdout or 'Recreated' in grafana_up.stdout"
|
||||||
|
|
||||||
- name: Wait for services to start
|
- name: Wait for Grafana to start
|
||||||
ansible.builtin.pause:
|
ansible.builtin.wait_for:
|
||||||
seconds: 20
|
host: "{{ server_ips.manage }}"
|
||||||
|
port: "{{ grafana_port }}"
|
||||||
|
timeout: 60
|
||||||
|
state: started
|
||||||
|
become: no
|
||||||
|
|
||||||
- name: Check Grafana container status
|
- name: Check Grafana container status
|
||||||
ansible.builtin.shell: docker ps --filter name=grafana
|
ansible.builtin.shell: |
|
||||||
|
docker ps --filter name=grafana --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
register: grafana_status
|
register: grafana_status
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Show Grafana status
|
- name: Show Grafana status
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
var: grafana_status.stdout_lines
|
var: grafana_status.stdout
|
||||||
|
|
||||||
- name: Ensure datasources directory exists
|
- name: Check VictoriaMetrics connectivity from Grafana
|
||||||
ansible.builtin.file:
|
ansible.builtin.shell: |
|
||||||
path: "{{ grafana_config_dir }}/datasources"
|
docker exec grafana curl -s http://victoriametrics:8428/health
|
||||||
state: directory
|
register: vm_health_check
|
||||||
owner: 472
|
changed_when: false
|
||||||
group: 472
|
ignore_errors: yes
|
||||||
mode: '0755'
|
|
||||||
become: yes
|
|
||||||
|
|
||||||
- name: Deploy Loki datasource configuration
|
- name: Show VictoriaMetrics health check
|
||||||
template:
|
ansible.builtin.debug:
|
||||||
src: loki-datasource.yml.j2
|
var: vm_health_check.stdout
|
||||||
dest: "{{ grafana_config_dir }}/datasources/loki.yml"
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: '0644'
|
|
||||||
become: yes
|
|
||||||
@ -43,10 +43,10 @@ services:
|
|||||||
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_admin_password }}
|
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_admin_password }}
|
||||||
- GF_USERS_ALLOW_SIGN_UP=false
|
- GF_USERS_ALLOW_SIGN_UP=false
|
||||||
- GF_SERVER_ROOT_URL={{ grafana_root_url }}
|
- GF_SERVER_ROOT_URL={{ grafana_root_url }}
|
||||||
|
- GF_INSTALL_PLUGINS=grafana-clock-panel
|
||||||
volumes:
|
volumes:
|
||||||
- {{ grafana_data_dir }}:/var/lib/grafana
|
- {{ grafana_data_dir }}:/var/lib/grafana
|
||||||
- {{ grafana_config_dir }}:/etc/grafana/provisioning
|
- {{ grafana_config_dir }}/provisioning:/etc/grafana/provisioning
|
||||||
- {{ grafana_config_dir }}/datasources:/etc/grafana/provisioning/datasources
|
|
||||||
ports:
|
ports:
|
||||||
- "{{ grafana_port }}:3000"
|
- "{{ grafana_port }}:3000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
14
roles/grafana/templates/victoriametrics-datasource.yml.j2
Normal file
14
roles/grafana/templates/victoriametrics-datasource.yml.j2
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: 1
|
||||||
|
|
||||||
|
datasources:
|
||||||
|
- name: VictoriaMetrics
|
||||||
|
type: prometheus
|
||||||
|
access: proxy
|
||||||
|
url: http://victoriametrics:8428
|
||||||
|
isDefault: true
|
||||||
|
version: 1
|
||||||
|
editable: true
|
||||||
|
jsonData:
|
||||||
|
timeInterval: 30s
|
||||||
|
queryTimeout: 60s
|
||||||
|
httpMethod: POST
|
||||||
Loading…
Reference in New Issue
Block a user