-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafana_gnocchi_collectd.yaml
170 lines (148 loc) · 4.29 KB
/
grafana_gnocchi_collectd.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
- hosts: localhost
tasks:
- name: Install rdo pike and opstools repositories
package:
name: '{{ item }}'
with_items:
- centos-release-opstools
- centos-release-openstack-pike
become: true
- name: Install grafana repo
blockinfile:
dest: /etc/yum.repos.d/grafana.repo
create: yes
block: |
[grafana]
baseurl = https://packagecloud.io/grafana/stable/el/7/x86_64
gpgcheck = 1
gpgkey = https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana
name = Grafana repository
become: true
- name: Install all packages from repositories
package:
name: '{{ item }}'
with_items:
- collectd
- collectd-disk
- collectd-python
- mariadb-server
- openstack-gnocchi-api
- openstack-gnocchi-metricd
- python-pip
- grafana
become: true
- name: Install grafana-gnocchi datasource plugin
shell: 'grafana-cli plugins install gnocchixyz-gnocchi-datasource'
become: true
- name: Install collectd-gnocchi plugin
shell: 'pip install collectd-gnocchi'
become: true
- name: Start database
systemd:
name: mariadb
enabled: yes
state: started
become: true
- name: Create gnocchi db
mysql_db:
name: gnocchi
state: present
become: true
- name: Create gnocchi db user
mysql_user:
name: gnocchi
password: p4assw0rd
priv: 'gnocchi.*:ALL'
state: present
become: true
- name: Configure gnocchi
replace:
dest: /etc/gnocchi/gnocchi.conf
regexp: '#url = <None>'
replace: 'url = mysql://gnocchi:p4assw0rd@localhost/gnocchi'
become: true
- name: Populate gnocchi db
shell: gnocchi-upgrade
become: true
- name: Ensure /var/lib/gnocchi is owned by gnocchi user
file:
path: /var/lib/gnocchi
owner: gnocchi
group: gnocchi
state: directory
recurse: yes
become: true
- name: Configure gnocchi api service
replace:
dest: /usr/lib/systemd/system/openstack-gnocchi-api.service
regexp: 'ExecStart=.*'
replace: 'ExecStart=/usr/bin/gnocchi-api -p 8041 -- --log-file /var/log/gnocchi/api.log'
become: true
- name: Configure grafana
ini_file:
dest: /etc/grafana/grafana.ini
section: auth.basic
option: enabled
value: true
become: true
- name: Disable SELinux (config)
selinux:
state: disabled
become: true
- name: Disable SELinux
shell: 'setenforce 0'
become: true
#- name: Install default dashboard
#- copy:
#- src: grafana-gnocchi-collectd.json
#- dest: /usr/share/grafana/public/dashboards/home.json
#- become: true
- name: Start daemons
systemd:
name: '{{ item }}'
enabled: yes
state: started
daemon_reload: yes
with_items:
- openstack-gnocchi-api
- openstack-gnocchi-metricd
- grafana-server
become: true
- name: Wait for grafana db initialization
wait_for:
port: 3000
host: localhost
- name: Get datasources
uri:
url: http://localhost:3000/api/datasources
method: GET
user: admin
password: admin
force_basic_auth: "yes"
register: datasources
- name: set datasource fact
set_fact:
grafana_datasources: "{{ datasources.json | default([]) | map(attribute='name') | list }}"
- name: Configure datasource
uri:
url: http://localhost:3000/api/datasources
method: POST
user: admin
password: admin
body: '{{ grafana_data_source | to_json }}'
body_format: json
force_basic_auth: "yes"
when: grafana_data_source.name not in grafana_datasources
- name: Install collectd configurations files
synchronize:
src: collectd.d/
dest: /etc/collectd.d/
become: true
- name: Start collectd
systemd:
name: collectd
enabled: yes
state: started
daemon_reload: yes
become: true