Skip to content

Commit cdd7683

Browse files
bbezakdougszumski
authored andcommitted
Add support for custom grafana dashboards
Allow users to import custom grafana dashboards. Dashboards as JSON files should be placed into "{{ node_custom_config }}/grafana/dashboards/" folder. Change-Id: Id0f83b8d08541b3b74649f097b10c9450201b426
1 parent c431313 commit cdd7683

File tree

6 files changed

+145
-0
lines changed

6 files changed

+145
-0
lines changed

ansible/roles/grafana/tasks/config.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,71 @@
102102
- "prometheus.yaml.j2"
103103
notify:
104104
- Restart grafana container
105+
106+
- name: Configuring dashboards provisioning
107+
vars:
108+
service: "{{ grafana_services['grafana'] }}"
109+
template:
110+
src: "{{ item }}"
111+
dest: "{{ node_config_directory }}/grafana/provisioning.yaml"
112+
mode: "0660"
113+
become: true
114+
when:
115+
- inventory_hostname in groups[service.group]
116+
- service.enabled | bool
117+
with_first_found:
118+
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/provisioning.yaml"
119+
- "{{ node_custom_config }}/grafana/provisioning.yaml"
120+
- "{{ role_path }}/templates/provisioning.yaml.j2"
121+
notify:
122+
- Restart grafana container
123+
124+
- name: Check if the folder for custom grafana dashboards exists
125+
stat:
126+
path: "{{ node_custom_config }}/grafana/dashboards"
127+
delegate_to: localhost
128+
register: grafana_custom_dashboards_folder
129+
run_once: True
130+
131+
- name: Remove templated Grafana dashboards
132+
become: true
133+
vars:
134+
service: "{{ grafana_services['grafana'] }}"
135+
file:
136+
state: absent
137+
path: "{{ node_config_directory }}/grafana/dashboards/"
138+
when:
139+
- inventory_hostname in groups[service.group]
140+
- service.enabled | bool
141+
142+
- name: Create custom Grafana dashboards folder
143+
become: true
144+
vars:
145+
service: "{{ grafana_services['grafana'] }}"
146+
file:
147+
dest: "{{ node_config_directory }}/grafana/dashboards/"
148+
state: "directory"
149+
mode: "0770"
150+
when:
151+
- grafana_custom_dashboards_folder.stat.exists
152+
- grafana_custom_dashboards_folder.stat.isdir
153+
- inventory_hostname in groups[service.group]
154+
- service.enabled | bool
155+
156+
- name: Copying over custom dashboards
157+
vars:
158+
service: "{{ grafana_services['grafana'] }}"
159+
copy:
160+
src: "{{ item }}"
161+
dest: "{{ node_config_directory }}/grafana/dashboards/"
162+
mode: "0660"
163+
become: true
164+
when:
165+
- grafana_custom_dashboards_folder.stat.exists
166+
- grafana_custom_dashboards_folder.stat.isdir
167+
- inventory_hostname in groups[service.group]
168+
- service.enabled | bool
169+
with_fileglob:
170+
- "{{ node_custom_config }}/grafana/dashboards/*.json"
171+
notify:
172+
- Restart grafana container

ansible/roles/grafana/templates/grafana.json.j2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
"owner": "root",
2929
"perm": "0644",
3030
"optional": true
31+
},
32+
{
33+
"source": "{{ container_config_directory }}/provisioning.yaml",
34+
"dest": "/etc/grafana/provisioning/dashboards/provisioning.yaml",
35+
"owner": "root",
36+
"perm": "0644"
37+
},
38+
{
39+
"source": "{{ container_config_directory }}/dashboards/",
40+
"dest": "/var/lib/grafana/dashboards",
41+
"owner": "grafana",
42+
"perm": "0755",
43+
"optional": true
3144
}
3245
],
3346
"permissions": [
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# # config file version
2+
apiVersion: 1
3+
4+
providers:
5+
- name: 'default'
6+
orgId: 1
7+
folder: ''
8+
folderUid: ''
9+
type: file
10+
options:
11+
path: /var/lib/grafana/dashboards
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.. _grafana-guide:
2+
3+
=======
4+
Grafana
5+
=======
6+
7+
Overview
8+
~~~~~~~~
9+
10+
`Grafana <https://grafana.com>`_ is open and composable observability and
11+
data visualization platform. Visualize metrics, logs, and traces from
12+
multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB,
13+
Postgres and many more..
14+
15+
Preparation and deployment
16+
~~~~~~~~~~~~~~~~~~~~~~~~~~
17+
18+
To enable Grafana, modify the configuration file ``/etc/kolla/globals.yml``
19+
and change the following:
20+
21+
.. code-block:: yaml
22+
23+
enable_grafana: "yes"
24+
25+
If you would like to set up Prometheus as a data source additionally set:
26+
27+
.. code-block:: yaml
28+
29+
enable_prometheus: "yes"
30+
31+
Please follow :doc:`Prometheus Guide <prometheus-guide>` for more information
32+
33+
Custom Dashboards Provisioning
34+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
36+
Kolla Ansible sets Custom Dashboards Provisioning using `Dashboard provider <https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards>`_.
37+
38+
Dashboard's JSON files should be placed into
39+
``{{ node_custom_config }}/grafana/dashboards/`` folder.
40+
Dashboards will be imported to Grafana dashboards General Folder.
41+
42+
Grafana provisioner config can be altered by placing ``provisioning.yaml`` to
43+
``{{ node_custom_config }}/grafana/`` folder.
44+
45+
For other settings follow configuration reference:
46+
`Dashboard provider configuration <https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards>`_.

doc/source/reference/logging-and-monitoring/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ logging and monitoring services available in kolla.
99
:maxdepth: 1
1010

1111
central-logging-guide
12+
grafana-guide
1213
influxdb-guide
1314
kafka-guide
1415
monasca-guide
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Adds support to import custom ``grafana`` dashboards. Dashboard's JSON
5+
files should be placed into "{{ node_custom_config }}/grafana/dashboards/"
6+
folder.

0 commit comments

Comments
 (0)