diff --git a/ansible/roles/monitoring/tasks/panel.yml b/ansible/roles/monitoring/tasks/panel.yml index b7abd08..4ce254b 100644 --- a/ansible/roles/monitoring/tasks/panel.yml +++ b/ansible/roles/monitoring/tasks/panel.yml @@ -15,20 +15,43 @@ - { src: ".env", dest: ".env" } # ansible -i inventories/prod -m setup heroctf-static-1 -- name: Collect IP addresses from challenges +- name: Collect IP addresses from challenges (cAdvisor) ansible.builtin.set_fact: cadvisor_targets: >- {% for host in groups['static-challenges'] + groups['dynamic-challenges'] -%} - , "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:1080" + - targets: + - "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:1080" + labels: + instance: "containers-{{ hostvars[host]['ansible_hostname'] }}" + {{''}} {%- endfor -%} -- name: Collect IP addresses from challenges +- name: Collect IP addresses from challenges (node-exporter) ansible.builtin.set_fact: nodeexporter_targets: >- {% for host in groups['static-challenges'] + groups['dynamic-challenges'] -%} - , "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:9100" + - targets: + - "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:9100" + labels: + instance: "vm-{{ hostvars[host]['ansible_hostname'] }}" + {{''}} {%- endfor -%} +# - name: Collect IP addresses from challenges (/etc/hosts) +# ansible.builtin.set_fact: +# hosts_content: >- +# {% for host in groups['static-challenges'] + groups['dynamic-challenges'] %} +# {{ hostvars[host]['ansible_eth1']['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} +# {% endfor %} + +# - name: Populate /etc/hosts with 'hosts_content' +# ansible.builtin.lineinfile: +# path: /etc/hosts +# line: "{{ item }}" +# state: present +# loop: "{{ hosts_content.splitlines() }}" +# become: true + - name: "Setup Prometheus configuration" ansible.builtin.template: src: prometheus.yml.j2 diff --git a/ansible/roles/monitoring/templates/prometheus.yml.j2 b/ansible/roles/monitoring/templates/prometheus.yml.j2 index 31bb870..b159bb2 100644 --- a/ansible/roles/monitoring/templates/prometheus.yml.j2 +++ b/ansible/roles/monitoring/templates/prometheus.yml.j2 @@ -9,8 +9,20 @@ scrape_configs: - job_name: "cadvisor" static_configs: - - targets: ["cadvisor:8080", "35.180.196.232:8080" {{ cadvisor_targets }}] + - targets: + - "35.180.196.232:8080" + labels: + instance: "containers-ctfd" + - targets: + - "cadvisor:8080" + labels: + instance: "containers-deploy-dynamic" + {{ cadvisor_targets }} - job_name: "node" static_configs: - - targets: ["node_exporter:9100" {{ nodeexporter_targets }}] + - targets: + - "node_exporter:9100" + labels: + instance: "vm-deploy-dynamic" + {{ nodeexporter_targets }}