Automatically add Prometheus as a Grafana datasource

Assuming both Prometheus and Grafana are enabled, this change
configures Grafana such that it can use data collected by the
Prometheus server.

Partially-Implements: blueprint prometheus
Change-Id: I0290806d0c622b1de33cf7047f099795b4c780b9
This commit is contained in:
Mark Giles 2018-04-18 15:52:09 -04:00
parent 32fa09968b
commit 6777c903a0
5 changed files with 38 additions and 0 deletions

View File

@ -20,3 +20,4 @@
or grafana_conf.changed | bool
or grafana_container.changed | bool
or grafana_home_dashboard.changed | bool
or grafana_prometheus_data_source.changed | bool

View File

@ -80,6 +80,26 @@
notify:
- Restart grafana container
- name: Configuring Prometheus as data source for Grafana
vars:
service: "{{ grafana_services['grafana'] }}"
template:
src: "{{ item }}"
dest: "{{ node_config_directory }}/grafana/prometheus.yaml"
mode: "0660"
become: true
register: grafana_prometheus_data_source
when:
- inventory_hostname in groups[service.group]
- service.enabled | bool
- enable_prometheus | bool
with_first_found:
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/prometheus.yaml"
- "{{ node_custom_config }}/grafana/prometheus.yaml"
- "prometheus.yaml.j2"
notify:
- Restart grafana container
- name: Check grafana containers
kolla_docker:
action: "compare_container"

View File

@ -2,6 +2,7 @@
data = /var/lib/grafana
logs = /var/log/kolla/grafana
plugins = /var/lib/grafana/plugins
provisioning = /etc/grafana/provisioning
[server]
protocol = http

View File

@ -21,6 +21,13 @@
"owner": "root",
"perm": "0644",
"optional": true
},
{
"source": "{{ container_config_directory }}/prometheus.yaml",
"dest": "/etc/grafana/provisioning/datasources/prometheus.yaml",
"owner": "root",
"perm": "0644",
"optional": true
}
],
"permissions": [

View File

@ -0,0 +1,9 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
orgId: 1
url: http://{{ kolla_internal_vip_address }}:{{ prometheus_port }}
version: 1