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

Commit

Permalink
add prometheus as container
Browse files Browse the repository at this point in the history
  • Loading branch information
l3d00m committed Jan 3, 2024
1 parent 1180f14 commit 5dcdcab
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
4 changes: 4 additions & 0 deletions roles/monitoring/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ monitoring_domain: monitoring.{{ app_domain }}
grafana_install_location: "/srv/grafana"
grafana_data_location: "{{ grafana_install_location }}/data"

prometheus_install_location: "/srv/prometheus"
prometheus_data_location: "{{ prometheus_install_location }}/data"
prometheus_config_location: "{{ prometheus_install_location }}/prometheus.yml"

grafana_port: "3000"
10 changes: 4 additions & 6 deletions roles/monitoring/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
- name: reload prometheus
ansible.builtin.service:
name: prometheus
state: restarted

- name: reload grafana
- name: reload monitoring
community.docker.docker_stack:
state: present
name: "monitoring"
Expand All @@ -14,3 +9,6 @@

- name: wait for grafana
ansible.builtin.command: "docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock sudobmitch/docker-stack-wait -n grafana monitoring"

- name: wait for prometheus
ansible.builtin.command: "docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock sudobmitch/docker-stack-wait -n grafana monitoring"
17 changes: 6 additions & 11 deletions roles/monitoring/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
- name: Install packages
ansible.builtin.package:
name:
- prometheus
state: present

- name: Create install directory
ansible.builtin.file:
path: "{{ item }}"
Expand All @@ -13,6 +7,7 @@
group: "root"
with_items:
- "{{ grafana_install_location }}"
- "{{ prometheus_install_location }}"
become: true

- name: Create data directories
Expand All @@ -24,9 +19,8 @@
group: "root"
with_items:
- "{{ grafana_data_location }}"
- "{{ prometheus_data_location }}"
become: true
tags:
- grafana

- name: Create docker-compose.yml
ansible.builtin.template:
Expand All @@ -38,18 +32,19 @@
validate: docker-compose -f %s config -q
become: true
notify:
- reload grafana
- reload monitoring
- wait for grafana

- name: Copy prometheus config
ansible.builtin.copy:
src: prometheus.yml
dest: /etc/prometheus/prometheus.yml
dest: "{{ prometheus_config_location }}"
owner: root
group: root
mode: "0644"
notify:
- reload prometheus
- reload monitoring
- wait for prometheus
# - name: Expose DB tasks
# ansible.builtin.include_tasks: expose_db.yml
# vars:
Expand Down
22 changes: 22 additions & 0 deletions roles/monitoring/templates/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ services:
delay: 5s
max_attempts: 3
window: 120s
prometheus:
image: prom/prometheus
networks:
{{ db_network }}:
volumes:
- "{{prometheus_data_location}}:/prometheus"
- "{{prometheus_config_location}}:/etc/prometheus/prometheus.yml"
restart: always
deploy:
update_config:
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: start-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s


networks:
{{ proxy_network }}:
Expand Down

0 comments on commit 5dcdcab

Please sign in to comment.