From c201bc7a636b275df8a45acf5ef199a333873db3 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Sat, 1 Jun 2024 20:09:04 +0100 Subject: Update Prometheus config to include Postgres exporter We dynamically fetch all hosts in the databases group and add them to the scrape targets with the PostgreSQL exporter port (9187) --- ansible/host_vars/lovelace/prometheus.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'ansible') diff --git a/ansible/host_vars/lovelace/prometheus.yml b/ansible/host_vars/lovelace/prometheus.yml index 6d1d098..ca9fc9c 100644 --- a/ansible/host_vars/lovelace/prometheus.yml +++ b/ansible/host_vars/lovelace/prometheus.yml @@ -19,7 +19,9 @@ prometheus_web_configuration: - prometheus.access.tls.pydis.wtf - sudo.access.tls.pydis.wtf -prometheus_configuration: +prometheus_configuration: | + #jinja2: trim_blocks:False + global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. @@ -55,7 +57,18 @@ prometheus_configuration: - job_name: node # Scrape node exporters on all hosts static_configs: - - targets: "{{ hostvars.values() | map(attribute='ansible_wg0.ipv4.address') | map('regex_replace', '^(.*)$', '\\1:9100') | list }}" + - targets: + {%- for host in hostvars.values() %} + - {{ host['ansible_wg0']['ipv4']['address'] }}:9100 + {%- endfor %} + + - job_name: postgres + # Scrape PostgreSQL metrics from database hosts + static_configs: + - targets: + {%- for host in groups['databases'] %} + - {{ hostvars[host]['ansible_wg0']['ipv4']['address'] }}:9187 + {%- endfor %} - job_name: blackbox-ssh metrics_path: /probe -- cgit v1.2.3