mirror of
https://github.com/status-im/infra-role-grafana.git
synced 2025-02-22 09:18:24 +00:00
refactor use use Docker Compose to create containers
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
7dccd21b29
commit
9f8009520d
@ -19,7 +19,7 @@ grafana_prometheus_sources:
|
|||||||
You should also configure OAuth:
|
You should also configure OAuth:
|
||||||
```yaml
|
```yaml
|
||||||
grafana_oauth_id: '123qwe123qwe123'
|
grafana_oauth_id: '123qwe123qwe123'
|
||||||
grafana_oauth_secret: 'qweasdqweasdqweasdqweasd
|
grafana_oauth_secret: 'qweasdqweasdqweasdqweasd'
|
||||||
grafana_oauth_gh_org: 'evil-corp'
|
grafana_oauth_gh_org: 'evil-corp'
|
||||||
grafana_oauth_gh_team_ids: [ 1234, 5678 ]
|
grafana_oauth_gh_team_ids: [ 1234, 5678 ]
|
||||||
```
|
```
|
||||||
|
@ -1,21 +1,27 @@
|
|||||||
---
|
---
|
||||||
|
grafana_service_name: 'grafana'
|
||||||
|
grafana_service_path: '/docker/{{ grafana_service_name }}'
|
||||||
|
grafana_compose_file: '{{ grafana_service_path }}/docker-compose.yml'
|
||||||
|
# Container
|
||||||
|
grafana_version: '7.3.4'
|
||||||
|
grafana_image: 'grafana/grafana:{{ grafana_version }}'
|
||||||
|
grafana_cont_name: '{{ grafana_service_name }}'
|
||||||
|
grafana_cont_vol: '{{ grafana_service_path }}/data'
|
||||||
|
grafana_cont_links: []
|
||||||
|
grafana_cont_ext_links: []
|
||||||
|
grafana_port: 9400
|
||||||
|
# see: http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later
|
||||||
|
grafana_cont_uid: 472
|
||||||
|
# Permission adjust for dockremap.
|
||||||
|
grafana_host_uid: '{{ 100000 + grafana_cont_uid | int }}'
|
||||||
|
|
||||||
|
# Public domain
|
||||||
grafana_domain: ~
|
grafana_domain: ~
|
||||||
|
|
||||||
# Main configuration for sources
|
# Main configuration for sources
|
||||||
grafana_prometheus_sources: []
|
grafana_prometheus_sources: []
|
||||||
# - { name: 'node-01', addr: '1.2.3.4', port: 8080, path: 'proxy/' }
|
# - { name: 'node-01', addr: '1.2.3.4', port: 8080, path: 'proxy/' }
|
||||||
|
|
||||||
grafana_version: '7.3.4'
|
|
||||||
grafana_image: 'grafana/grafana:{{ grafana_version }}'
|
|
||||||
grafana_cont_name: grafana
|
|
||||||
grafana_cont_vol: '/docker/grafana'
|
|
||||||
grafana_cont_links: []
|
|
||||||
grafana_port: 9400
|
|
||||||
# see: http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later
|
|
||||||
grafana_cont_uid: 472
|
|
||||||
# adjust for dockremap
|
|
||||||
grafana_host_uid: '{{ 100000 + grafana_cont_uid | int }}'
|
|
||||||
|
|
||||||
# Admin user
|
# Admin user
|
||||||
grafana_username: ~
|
grafana_username: ~
|
||||||
grafana_password: ~
|
grafana_password: ~
|
||||||
@ -45,9 +51,7 @@ grafana_snaphots_enabled: true
|
|||||||
grafana_plugins:
|
grafana_plugins:
|
||||||
- https://github.com/GoshPosh/grafana-meta-queries/archive/0.0.3.zip
|
- https://github.com/GoshPosh/grafana-meta-queries/archive/0.0.3.zip
|
||||||
|
|
||||||
|
# Generic container options
|
||||||
|
compose_recreate: 'smart'
|
||||||
# generic container settings
|
compose_state: 'present'
|
||||||
cont_state: started
|
compose_restart: false
|
||||||
cont_restart: false
|
|
||||||
cont_recreate: false
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
- name: restart grafana
|
|
||||||
docker_container:
|
|
||||||
name: '{{ grafana_cont_name }}'
|
|
||||||
restart: true
|
|
@ -1,4 +1,13 @@
|
|||||||
---
|
---
|
||||||
|
- name: Create grafana directories
|
||||||
|
file:
|
||||||
|
path: '{{ grafana_cont_vol }}'
|
||||||
|
state: directory
|
||||||
|
owner: 'dockremap'
|
||||||
|
group: 'docker'
|
||||||
|
mode: 0775
|
||||||
|
recurse: true
|
||||||
|
|
||||||
- name: Create grafana directories
|
- name: Create grafana directories
|
||||||
file:
|
file:
|
||||||
path: '{{ item }}'
|
path: '{{ item }}'
|
||||||
@ -8,18 +17,20 @@
|
|||||||
mode: 0775
|
mode: 0775
|
||||||
recurse: true
|
recurse: true
|
||||||
with_items:
|
with_items:
|
||||||
- '{{ grafana_cont_vol }}'
|
- '{{ grafana_cont_vol }}/etc'
|
||||||
- '{{ grafana_cont_vol }}/etc/provisioning/datasources'
|
- '{{ grafana_cont_vol }}/etc/provisioning/datasources'
|
||||||
|
- '{{ grafana_cont_vol }}/lib'
|
||||||
- '{{ grafana_cont_vol }}/lib/plugins'
|
- '{{ grafana_cont_vol }}/lib/plugins'
|
||||||
- '{{ grafana_cont_vol }}/lib/dashboards'
|
- '{{ grafana_cont_vol }}/lib/dashboards'
|
||||||
|
|
||||||
- name: Copy grafana config file
|
- name: Generate main config file
|
||||||
template:
|
template:
|
||||||
src: 'grafana.ini.j2'
|
src: 'grafana.ini.j2'
|
||||||
dest: '{{ grafana_cont_vol }}/etc/grafana.ini'
|
dest: '{{ grafana_cont_vol }}/etc/grafana.ini'
|
||||||
owner: '{{ grafana_host_uid }}'
|
owner: '{{ grafana_host_uid }}'
|
||||||
group: docker
|
group: docker
|
||||||
register: cont_conf
|
mode: 0640
|
||||||
|
register: grafana_config
|
||||||
|
|
||||||
- name: Generate datasource config file
|
- name: Generate datasource config file
|
||||||
template:
|
template:
|
||||||
@ -27,9 +38,9 @@
|
|||||||
dest: '{{ grafana_cont_vol }}/etc/provisioning/datasources/prometheus.yml'
|
dest: '{{ grafana_cont_vol }}/etc/provisioning/datasources/prometheus.yml'
|
||||||
owner: '{{ grafana_host_uid }}'
|
owner: '{{ grafana_host_uid }}'
|
||||||
group: docker
|
group: docker
|
||||||
notify: restart grafana
|
mode: 0640
|
||||||
|
|
||||||
- name: Install plugins from zip archives
|
- name: Install plugins from ZIP archives
|
||||||
unarchive:
|
unarchive:
|
||||||
src: '{{ item }}'
|
src: '{{ item }}'
|
||||||
dest: '{{ grafana_cont_vol }}/lib/plugins'
|
dest: '{{ grafana_cont_vol }}/lib/plugins'
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
- name: Create Consul service definition
|
- name: Create Consul service definition
|
||||||
include_role: name=consul-service
|
include_role: name=consul-service
|
||||||
vars:
|
vars:
|
||||||
consul_config_name: 'grafana'
|
consul_config_name: '{{ grafana_service_name }}'
|
||||||
consul_services:
|
consul_services:
|
||||||
- name: 'grafana'
|
- name: '{{ grafana_service_name }}'
|
||||||
tags: ['monitor', 'metrics-view']
|
tags: ['monitor', 'grafana']
|
||||||
port: '{{ grafana_port }}'
|
port: '{{ grafana_port }}'
|
||||||
checks:
|
checks:
|
||||||
- id: grafana-health
|
- id: '{{ grafana_service_name }}-health'
|
||||||
name: Grafana current health
|
name: 'Grafana current health'
|
||||||
type: http
|
type: 'http'
|
||||||
http: 'http://localhost:{{ grafana_port }}/api/health'
|
http: 'http://localhost:{{ grafana_port }}/api/health'
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
---
|
---
|
||||||
- name: Start grafana container
|
- name: Create compose file
|
||||||
docker_container:
|
template:
|
||||||
name: '{{ grafana_cont_name }}'
|
src: 'docker-compose.yml.j2'
|
||||||
image: '{{ grafana_image }}'
|
dest: '{{ grafana_compose_file }}'
|
||||||
|
owner: 'dockremap'
|
||||||
|
group: 'docker'
|
||||||
|
mode: 0640
|
||||||
|
|
||||||
|
- name: Create containers
|
||||||
|
docker_compose:
|
||||||
|
project_src: '{{ grafana_service_path }}'
|
||||||
pull: true
|
pull: true
|
||||||
restart_policy: always
|
build: false
|
||||||
state: '{{ cont_state }}'
|
state: '{{ compose_state }}'
|
||||||
recreate: '{{ cont_recreate }}'
|
restarted: '{{ compose_restart }}'
|
||||||
restart: '{{ cont_conf.changed | default(cont_restart) }}'
|
recreate: '{{ grafana_config.changed | ternary("always", compose_recreate) }}'
|
||||||
ports:
|
|
||||||
- '127.0.0.1:{{ grafana_port }}:3000'
|
|
||||||
links: '{{ grafana_cont_links }}'
|
|
||||||
volumes:
|
|
||||||
- '{{ grafana_cont_vol }}/lib:/var/lib/grafana'
|
|
||||||
- '{{ grafana_cont_vol }}/etc:/etc/grafana'
|
|
||||||
|
18
templates/docker-compose.yml.j2
Normal file
18
templates/docker-compose.yml.j2
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
version: '3.7'
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
container_name: '{{ grafana_cont_name }}'
|
||||||
|
image: '{{ grafana_image }}'
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- '127.0.0.1:{{ grafana_port }}:{{ grafana_port }}'
|
||||||
|
volumes:
|
||||||
|
- '{{ grafana_cont_vol }}/lib:/var/lib/grafana'
|
||||||
|
- '{{ grafana_cont_vol }}/etc:/etc/grafana'
|
||||||
|
{% if grafana_cont_ext_links|length > 0 %}
|
||||||
|
external_links: {{ grafana_cont_ext_links | to_yaml }}
|
||||||
|
{% endif %}
|
||||||
|
{% if grafana_cont_links|length > 0 %}
|
||||||
|
links: {{ grafana_cont_links | to_yaml }}
|
||||||
|
{% endif %}
|
@ -1,4 +1,5 @@
|
|||||||
[server]
|
[server]
|
||||||
|
http_port = {{ grafana_port }}
|
||||||
domain = {{ grafana_domain | mandatory }}/
|
domain = {{ grafana_domain | mandatory }}/
|
||||||
root_url = https://{{ grafana_domain | mandatory }}/
|
root_url = https://{{ grafana_domain | mandatory }}/
|
||||||
|
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
apiVersion: 1
|
apiVersion: 1
|
||||||
|
|
||||||
deleteDatasources:
|
|
||||||
{% for service in grafana_prometheus_sources %}
|
|
||||||
- id: {{ loop.index }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
datasources:
|
datasources:
|
||||||
{% for service in grafana_prometheus_sources %}
|
{% for service in grafana_prometheus_sources %}
|
||||||
- name: {{ service.name }}
|
- name: {{ service.name }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user