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
@ -4,4 +4,10 @@
|
||||
project_src: "{{ grafana_base_dir }}"
|
||||
state: restarted
|
||||
services: vmagent
|
||||
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:
|
||||
- "{{ grafana_base_dir }}"
|
||||
- "{{ grafana_data_dir }}"
|
||||
- "{{ grafana_config_dir }}"
|
||||
- "{{ grafana_config_dir }}/provisioning/datasources"
|
||||
- "{{ grafana_config_dir }}/provisioning/dashboards"
|
||||
- "{{ 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
|
||||
template:
|
||||
@ -31,42 +40,59 @@
|
||||
group: root
|
||||
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
|
||||
ansible.builtin.shell: |
|
||||
cd "{{ grafana_base_dir }}"
|
||||
docker compose down
|
||||
docker compose up -d
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: grafana_up
|
||||
changed_when: "'Started' in grafana_up.stdout or 'Recreated' in grafana_up.stdout"
|
||||
|
||||
- name: Wait for services to start
|
||||
ansible.builtin.pause:
|
||||
seconds: 20
|
||||
- name: Wait for Grafana to start
|
||||
ansible.builtin.wait_for:
|
||||
host: "{{ server_ips.manage }}"
|
||||
port: "{{ grafana_port }}"
|
||||
timeout: 60
|
||||
state: started
|
||||
become: no
|
||||
|
||||
- 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
|
||||
changed_when: false
|
||||
|
||||
- name: Show Grafana status
|
||||
ansible.builtin.debug:
|
||||
var: grafana_status.stdout_lines
|
||||
var: grafana_status.stdout
|
||||
|
||||
- name: Ensure datasources directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ grafana_config_dir }}/datasources"
|
||||
state: directory
|
||||
owner: 472
|
||||
group: 472
|
||||
mode: '0755'
|
||||
become: yes
|
||||
- name: Check VictoriaMetrics connectivity from Grafana
|
||||
ansible.builtin.shell: |
|
||||
docker exec grafana curl -s http://victoriametrics:8428/health
|
||||
register: vm_health_check
|
||||
changed_when: false
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Deploy Loki datasource configuration
|
||||
template:
|
||||
src: loki-datasource.yml.j2
|
||||
dest: "{{ grafana_config_dir }}/datasources/loki.yml"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
become: yes
|
||||
- name: Show VictoriaMetrics health check
|
||||
ansible.builtin.debug:
|
||||
var: vm_health_check.stdout
|
||||
@ -43,10 +43,10 @@ services:
|
||||
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_admin_password }}
|
||||
- GF_USERS_ALLOW_SIGN_UP=false
|
||||
- GF_SERVER_ROOT_URL={{ grafana_root_url }}
|
||||
- GF_INSTALL_PLUGINS=grafana-clock-panel
|
||||
volumes:
|
||||
- {{ grafana_data_dir }}:/var/lib/grafana
|
||||
- {{ grafana_config_dir }}:/etc/grafana/provisioning
|
||||
- {{ grafana_config_dir }}/datasources:/etc/grafana/provisioning/datasources
|
||||
- {{ grafana_config_dir }}/provisioning:/etc/grafana/provisioning
|
||||
ports:
|
||||
- "{{ grafana_port }}:3000"
|
||||
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