Skip to content
This repository was archived by the owner on Sep 14, 2024. It is now read-only.

Commit 88ca3af

Browse files
committed
feat: provision grafana datasources automatically
1 parent 4e54fbd commit 88ca3af

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ansible-playbook -i hosts main.yml --vault-id <plaintext-file-with-vault-passwor
3333

3434
If you use the example `dump.sql`, the initial username is `test` and password `testtest`. It's recommended to create a new admin user, login as that and delete this initial user.
3535

36-
A grafana monitoring solution will be available at `monitoring.<yourdomain>`. Don't forget to configure it with a password. You can add a Mysql datasource in grafana with domain `mariadb:3306`. Username is `monitoring` and password is set using the `monitoring_db_password` variable (not yet working).
36+
A grafana monitoring solution will be available at `monitoring.<yourdomain>`. Don't forget to configure it with a password. You must create a user in the database with name `monitoring` and password like the variable `monitoring_db_password`. It should have the privileges `SELECT on *.*, PROCESS, REPLICATION CLIENT`.
3737

3838
## Important role variables
3939

roles/monitoring/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
22
monitoring_domain: monitoring.{{ app_domain }}
33
monitoring_network: monitoring
4+
45
grafana_install_location: "/srv/grafana"
56
grafana_data_location: "{{ grafana_install_location }}/data"
7+
grafana_provisioning_location: "{{ grafana_install_location }}/provisioning"
68

79
prometheus_install_location: "/srv/prometheus"
810
prometheus_data_location: "{{ prometheus_install_location }}/data"

roles/monitoring/tasks/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
with_items:
2121
- "{{ grafana_data_location }}"
2222
- "{{ prometheus_data_location }}"
23+
- "{{ grafana_provisioning_location }}/datasources"
2324
become: true
2425

2526
- name: Create networks
@@ -55,6 +56,17 @@
5556
notify:
5657
- reload monitoring
5758
- wait for prometheus
59+
60+
- name: Copy grafana datasources config
61+
ansible.builtin.template:
62+
src: grafana-datasources.yml.j2
63+
dest: "{{ grafana_provisioning_location }}/datasources/custom.yaml"
64+
owner: root
65+
group: root
66+
mode: "0644"
67+
notify:
68+
- reload monitoring
69+
- wait for grafana
5870
# - name: Expose DB tasks
5971
# ansible.builtin.include_tasks: expose_db.yml
6072
# vars:

roles/monitoring/templates/docker-compose.yml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
{{ monitoring_network }}:
1111
volumes:
1212
- "{{grafana_data_location}}:/var/lib/grafana"
13+
- "{{grafana_provisioning_location}}:/etc/grafana/provisioning/"
1314
environment:
1415
- GF_SERVER_ROOT_URL=https://%(domain)s/
1516
- GF_SERVER_ENFORCE_DOMAIN=true
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{ ansible_managed | comment }}
2+
3+
# Configuration file version
4+
apiVersion: 1
5+
6+
# List of data sources to insert/update depending on what's
7+
# available in the database.
8+
datasources:
9+
- name: Prometheus
10+
type: prometheus
11+
uid: prometheus_reims
12+
# <string, required> Sets the access mode, either proxy or direct (Server or Browser in the UI).
13+
# Some data sources are incompatible with any setting but proxy (Server).
14+
access: proxy
15+
url: "http://prometheus:{{prometheus_port}}"
16+
# <bool> Allows users to edit data sources from the Grafana UI.
17+
editable: true
18+
- name: REIMS production DB
19+
type: mysql
20+
uid: mariadb_reims
21+
access: proxy
22+
url: "mariadb:{{db_port}}"
23+
editable: true
24+
database: {{reims2_db_name}}
25+
user: monitoring
26+
secureJsonData:
27+
password: {{monitoring_db_password}}
28+
jsonData:
29+
maxOpenConns: 10
30+
timeInterval: "15s"

0 commit comments

Comments
 (0)