-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.yml
501 lines (424 loc) · 14.6 KB
/
site.yml
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# This is a prototype, and a number of improvements required for production standard deployment:
# - Use latest versions of software, playbooks used installed old versions (we would probably
# want to write our own playbooks).
# - Hide all web interfaces behind reverse proxies, and use these to refer to each other
# - Do not install Prometheus, Alertmanager etc if already exists
# - Each Prometheus metrics endpoint should deploy it's own configuration
# - Prometheus data would need to be purged periodically
# - Grafana requires proper authentication (this uses password stored as plaintext)
# - Grafana requires a better database backend than SQLite
# - Playbook could generally be better (structured, variable extraction, proper file permissions)
# THESE NEED TO BE INTEGRATED INTO RESEARCH
# - Could not install RabbitMQ stats exporter - requires Docker (same with Memcached)
# - Same with UWSGI stats exporter - this required building with go and was not straightforward
# - We are definitely seeing the rise of containerised small applications
# - Prometheus should run on each node. Alertmanager should be centralised
# - Alertmanager integrates with HipChat and can call APIs, could replace alerts
# - Is alertmanager callable?
# - Now is the time to ask the question ... what are we measuring?
# - With the webhook, did not call API to say alert no longer firing
---
- hosts: all
############################################################################
# Prometheus & Grafana for metrics collection & display
############################################################################
roles:
- williamyeh.prometheus
- ansiblebit.grafana
vars:
prometheus_components:
- prometheus
- node_exporter
- alertmanager
prometheus_conf_main: prometheus/prometheus.yml
prometheus_alertmanager_conf: prometheus/alertmanager.yml
prometheus_alertmanager_url: 'http://localhost:9093'
prometheus_node_exporter_opts: '--collectors.enabled conntrack,diskstats,entropy,filefd,filesystem,hwmon,loadavg,logind,mdadm,meminfo,netdev,netstat,ntp,sockstat,stat,textfile,time,uname,vmstat --collector.ntp.server ntp.ubuntu.com'
grafana_admin_password: "password"
grafana_conf_data: |
app_mode = development
[paths]
data = {{ grafana_dir_data }}
logs = {{ grafana_dir_log }}
plugins = {{ grafana_dir_plugins }}
[server]
protocol = http
http_port = {{ grafana_http_port }}
[database]
type = {{ grafana_database.type }}
host = {{ grafana_database.host }}
name = {{ grafana_database.name }}
user = {{ grafana_database.user }}
password = {{ grafana_database.password }}
path = {{ grafana_database.path }}
[session]
[analytics]
check_for_updates = true
[security]
admin_user = {{ grafana_admin_user }}
admin_password = {{ grafana_admin_password }}
[snapshots]
[users]
[auth.anonymous]
[auth.github]
[auth.google]
[auth.proxy]
[auth.basic]
[auth.ldap]
[smtp]
[emails]
[log]
mode = file
level = Info
[log.console]
[log.file]
[event_publisher]
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards
tasks:
- name: "deploy Prometheus alert rules"
copy:
src: "prometheus/alerts.rules"
dest: "{{ prometheus_rule_path }}/alerts.rules"
owner: root
group: root
mode: 0644
notify:
- restart prometheus
- name: "remove Grafana install detritus"
file:
path: "{{item}}"
state: absent
with_items:
- grafana_dir_conf
- grafana_dir_data
- grafana_dir_home
- grafana_dir_log
- grafana_dir_plugins
- name: "check if Prometheus data source set up"
uri:
url: http://localhost:3000/api/datasources/name/Prometheus
user: "{{grafana_admin_user}}"
password: "{{grafana_admin_password}}"
force_basic_auth: yes
register: grafana_prometheus
failed_when: false
changed_when: false
- name: "enable Prometheus Datasource"
uri:
url: http://localhost:3000/api/datasources
method: POST
user: "{{grafana_admin_user}}"
password: "{{grafana_admin_password}}"
body:
name: "Prometheus"
type: "prometheus"
url: "http://localhost:9090"
access: "proxy"
isDefault: true
force_basic_auth: yes
status_code: 200
body_format: json
when: grafana_prometheus.status == 404
############################################################################
# Install SW utilities
############################################################################
- name: "install virtualenv"
apt:
name: "{{item}}"
state: latest
update-cache: yes
with_items:
- ntp
- python-virtualenv
############################################################################
# NGINX & UWSGI for web and application servers
############################################################################
- name: "ensure web server packages are installed"
apt:
name: "{{item}}"
state: latest
update_cache: yes
with_items:
- nginx
- uwsgi
- uwsgi-plugin-python
- name: "ensure default configuration files absent"
file:
path: "{{item}}"
state: absent
with_items:
- /etc/nginx/sites-available/default
- /etc/nginx/sites-enabled/default
- name: "add NGINX extras to enable Prometheus plugin"
apt:
name: "{{item}}"
state: latest
update_cache: yes
with_items:
- nginx-extras
- name: "get NGINX Prometheus metrics plugin"
git:
repo: "https://github.com/knyar/nginx-lua-prometheus.git"
dest: /opt/nginx-lua-prometheus
- name: "deploy Prometheus metrics NGINX configuration"
copy:
src: prometheus/metrics.nginx.conf
dest: /etc/nginx/sites-available/prometheus-metrics.conf
owner: root
group: root
mode: 0644
notify:
- nginx reloaded
- name: "enable Prometheus metrics NGINX configuration"
file:
src: /etc/nginx/sites-available/prometheus-metrics.conf
dest: /etc/nginx/sites-enabled/prometheus-metrics.conf
state: link
force: yes
############################################################################
# Echo UWSGI parameters application
############################################################################
- name: "create echo UWSGI parameters software directory"
file:
dest: /opt/echo-uwsgi-parameters
state: directory
owner: root
group: root
mode: 0755
- name: "deploy echo UWSGI parameters software"
copy:
src: echo-uwsgi-parameters/app.py
dest: /opt/echo-uwsgi-parameters/app.py
owner: root
group: root
mode: 0644
notify:
- uwsgi restarted
- name: "deploy echo UWSGI parameters NGINX configuration"
copy:
src: echo-uwsgi-parameters/nginx.conf
dest: /etc/nginx/sites-available/echo-uwsgi-parameters.conf
owner: root
group: root
mode: 0644
notify:
- nginx reloaded
- name: "enable echo UWSGI parameters NGINX configuration"
file:
src: /etc/nginx/sites-available/echo-uwsgi-parameters.conf
dest: /etc/nginx/sites-enabled/echo-uwsgi-parameters.conf
state: link
force: yes
- name: "deploy echo UWSGI parameters UWSGI configuration"
copy:
src: echo-uwsgi-parameters/uwsgi.ini
dest: /etc/uwsgi/apps-available/echo-uwsgi-parameters.ini
owner: root
group: root
mode: 0644
notify:
- uwsgi restarted
- name: "enable echo UWSGI parameters UWSGI configuration"
file:
src: /etc/uwsgi/apps-available/echo-uwsgi-parameters.ini
dest: /etc/uwsgi/apps-enabled/echo-uwsgi-parameters.ini
state: link
force: yes
############################################################################
# RabbitMQ message server
############################################################################
- name: "install RabbitMQ"
apt:
name: rabbitmq-server
state: latest
update_cache: yes
- name: "configure RabbitMQ management plugin"
rabbitmq_plugin:
names: rabbitmq_management
state: enabled
notify:
- rabbitmq reloaded
- name: "create RabbitMQ admin user"
rabbitmq_user:
name: admin
state: present
password: password
tags: admin,monitoring
read_priv: ".*"
write_priv: ".*"
configure_priv: ".*"
notify:
- rabbitmq reloaded
############################################################################
# Post RabbitMQ message application
############################################################################
- name: "create post RabbitMQ message software directory"
file:
dest: /opt/post-rabbitmq-message
state: directory
owner: root
group: root
mode: 0755
- name: "copy post RabbitMQ message requirements.txt to machine"
copy:
src: post-rabbitmq-message/requirements.txt
dest: /opt/post-rabbitmq-message/requirements.txt
owner: root
group: root
mode: 0644
- name: "install post RabbitMQ message virtualenv deployment tools"
pip:
name: "{{item}}"
state: latest
virtualenv: /opt/post-rabbitmq-message/venv
with_items:
- pip
- setuptools
- name: "install post RabbitMQ message dependencies"
pip:
requirements: /opt/post-rabbitmq-message/requirements.txt
virtualenv: /opt/post-rabbitmq-message/venv
- name: "deploy post RabbitMQ message software"
copy:
src: post-rabbitmq-message/app.py
dest: /opt/post-rabbitmq-message/app.py
owner: root
group: root
mode: 0644
notify:
- uwsgi restarted
- name: "deploy post RabbitMQ message NGINX configuration"
copy:
src: post-rabbitmq-message/nginx.conf
dest: /etc/nginx/sites-available/post-rabbitmq-message.conf
owner: root
group: root
mode: 0644
notify:
- nginx reloaded
- name: "enable post RabbitMQ message NGINX configuration"
file:
src: /etc/nginx/sites-available/post-rabbitmq-message.conf
dest: /etc/nginx/sites-enabled/post-rabbitmq-message.conf
state: link
force: yes
- name: "deploy post RabbitMQ message UWSGI configuration"
copy:
src: post-rabbitmq-message/uwsgi.ini
dest: /etc/uwsgi/apps-available/post-rabbitmq-message.ini
owner: root
group: root
mode: 0644
notify:
- uwsgi restarted
- name: "enable post RabbitMQ message UWSGI configuration"
file:
src: /etc/uwsgi/apps-available/post-rabbitmq-message.ini
dest: /etc/uwsgi/apps-enabled/post-rabbitmq-message.ini
state: link
force: yes
############################################################################
# general process metrics application
############################################################################
- name: "create general process metrics software directory"
file:
dest: /opt/general-process-metrics
state: directory
owner: root
group: root
mode: 0755
- name: "copy general process metrics requirements.txt to machine"
copy:
src: general-process-metrics/requirements.txt
dest: /opt/general-process-metrics/requirements.txt
owner: root
group: root
mode: 0644
- name: "install general process metrics virtualenv deployment tools"
pip:
name: "{{item}}"
state: latest
virtualenv: /opt/general-process-metrics/venv
with_items:
- pip
- setuptools
- name: "install general process metrics dependencies"
pip:
requirements: /opt/general-process-metrics/requirements.txt
virtualenv: /opt/general-process-metrics/venv
- name: "deploy general process metrics software"
copy:
src: general-process-metrics/app.py
dest: /opt/general-process-metrics/app.py
owner: root
group: root
mode: 0644
notify:
- uwsgi restarted
- name: "deploy general process metrics NGINX configuration"
copy:
src: general-process-metrics/nginx.conf
dest: /etc/nginx/sites-available/general-process-metrics.conf
owner: root
group: root
mode: 0644
notify:
- nginx reloaded
- name: "enable general process metrics NGINX configuration"
file:
src: /etc/nginx/sites-available/general-process-metrics.conf
dest: /etc/nginx/sites-enabled/general-process-metrics.conf
state: link
force: yes
- name: "deploy general process metrics UWSGI configuration"
copy:
src: general-process-metrics/uwsgi.ini
dest: /etc/uwsgi/apps-available/general-process-metrics.ini
owner: root
group: root
mode: 0644
notify:
- uwsgi restarted
- name: "enable general process metrics UWSGI configuration"
file:
src: /etc/uwsgi/apps-available/general-process-metrics.ini
dest: /etc/uwsgi/apps-enabled/general-process-metrics.ini
state: link
force: yes
############################################################################
# Grafana dashboards setup
############################################################################
- name: "create Grafana dashboards directory"
file:
dest: /var/lib/grafana/dashboards
state: directory
owner: grafana
group: grafana
mode: 0755
- name: "deploy Grafana dashboard configuration files"
copy:
src: "{{ item }}"
dest: /var/lib/grafana/dashboards/
owner: grafana
group: grafana
mode: 0644
with_fileglob:
"grafana/dashboards/*.json"
notify:
- restart grafana
handlers:
- name: "nginx reloaded"
service:
name: nginx
state: reloaded
- name: "uwsgi restarted"
service:
name: uwsgi
state: restarted
- name: "rabbitmq reloaded"
service:
name: rabbitmq-server
state: reloaded
...