@@ -66,12 +66,19 @@ scrape_configs:
6666 regex: "^(__tmp_keep_me)$"
6767
6868 static_configs:
69- {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project %}
69+ {% if hostvars [inventory_hostname ].nomad_mode == 'single' %}
70+ - targets: ['127.0.0.1:9100']
71+ labels:
72+ instance: "{{ inventory_hostname }}"
73+ project: "{{ prometheus_project }}"
74+ {% elif hostvars [inventory_hostname ].nomad_mode == 'cluster' %}
75+ {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project and item != inventory_hostname %}
7076 - targets: ['{{ hostvars[item] ['ansible_' + hostvars[item] .nomad_iface] ['ipv4'] ['address'] }}:9100']
7177 labels:
7278 instance: "{{ item }}"
7379 project: "{{ prometheus_project }}"
7480{% endfor %}
81+ {% endif %}
7582 scrape_interval: 60s
7683 scrape_timeout: 59s
7784
@@ -91,7 +98,7 @@ scrape_configs:
9198 params:
9299 script: [speedtest]
93100 static_configs:
94- - targets: ['127.0.0.1:9469']
101+ - targets: ['{% if hostvars [ inventory_hostname ]. nomad_mode == 'single' %} 127.0.0.1{% else %} {{ hostvars[inventory_hostnam e] ['ansible_' + nomad_ifac e] ['ipv4 '] ['address '] }} {% endif %} :9469']
95102 labels:
96103 instance: "{{ inventory_hostname }}"
97104 project: "{{ prometheus_project }}"
@@ -104,7 +111,7 @@ scrape_configs:
104111 regex: "^(go_|prometheus_|promhttp_).*"
105112 source_labels: [__name__]
106113 static_configs:
107- - targets: ['127.0.0.1:9469']
114+ - targets: ['{% if hostvars [ inventory_hostname ]. nomad_mode == 'single' %} 127.0.0.1{% else %} {{ hostvars[inventory_hostnam e] ['ansible_' + nomad_ifac e] ['ipv4 '] ['address '] }} {% endif %} :9469']
108115 labels:
109116 instance: "{{ inventory_hostname }}"
110117 project: "{{ prometheus_project }}"
@@ -115,7 +122,7 @@ scrape_configs:
115122 regex: "^(go_|prometheus_|promhttp_).*"
116123 source_labels: [__name__]
117124 static_configs:
118- - targets: ['127.0.0.1:15353']
125+ - targets: ['{% if hostvars [ inventory_hostname ]. nomad_mode == 'single' %} 127.0.0.1{% else %} {{ hostvars[inventory_hostnam e] ['ansible_' + nomad_ifac e] ['ipv4 '] ['address '] }} {% endif %} :15353']
119126 labels:
120127 instance: "{{ inventory_hostname }}"
121128 project: "{{ prometheus_project }}"
@@ -135,7 +142,7 @@ scrape_configs:
135142 - source_labels: ["__address__"]
136143 target_label: "instance"
137144 - target_label: "__address__"
138- replacement: "127.0.0.1:15353"
145+ replacement: "{% if hostvars [ inventory_hostname ]. nomad_mode == 'single' %} 127.0.0.1{% else %} {{ hostvars[inventory_hostnam e] ['ansible_' + nomad_ifac e] ['ipv4 '] ['address '] }} {% endif %} :15353"
139146 - target_label: "monitor"
140147 replacement: "{{ inventory_hostname }}"
141148 static_configs:
@@ -150,18 +157,27 @@ scrape_configs:
150157 regex: "^(go_|prometheus_|promhttp_).*"
151158 source_labels: [__name__]
152159 static_configs:
160+ {% if hostvars [inventory_hostname ].nomad_mode == 'single' %}
153161 - targets: ['127.0.0.1:9323']
154162 labels:
155163 instance: "{{ inventory_hostname }}"
156164 project: "{{ prometheus_project }}"
165+ {% elif hostvars [inventory_hostname ].nomad_mode == 'cluster' %}
166+ {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project and item != inventory_hostname %}
167+ - targets: ['{{ hostvars[item] ['ansible_' + hostvars[item] .nomad_iface] ['ipv4'] ['address'] }}:9323']
168+ labels:
169+ instance: "{{ item }}"
170+ project: "{{ prometheus_project }}"
171+ {% endfor %}
172+ {% endif %}
157173
158174 - job_name: "scan_exporter"
159175 metric_relabel_configs:
160176 - action: drop
161177 regex: "^(go_|prometheus_|promhttp_).*"
162178 source_labels: [__name__]
163179 static_configs:
164- - targets: ['127.0.0.1:2112']
180+ - targets: ['{% if hostvars [ inventory_hostname ]. nomad_mode == 'single' %} 127.0.0.1{% else %} {{ hostvars[inventory_hostnam e] ['ansible_' + nomad_ifac e] ['ipv4 '] ['address '] }} {% endif %} :2112']
165181 labels:
166182 instance: "{{ inventory_hostname }}"
167183 project: "{{ prometheus_project }}"
@@ -178,13 +194,19 @@ scrape_configs:
178194 tls_config:
179195 insecure_skip_verify: true
180196 static_configs:
181- {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project %}
197+ {% if hostvars [inventory_hostname ].nomad_mode == 'single' %}
198+ - targets: ['127.0.0.1:9558']
199+ labels:
200+ instance: "{{ inventory_hostname }}"
201+ project: "{{ prometheus_project }}"
202+ {% elif hostvars [inventory_hostname ].nomad_mode == 'cluster' %}
203+ {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project and item != inventory_hostname %}
182204 - targets: ['{{ hostvars[item] ['ansible_' + hostvars[item] .nomad_iface] ['ipv4'] ['address'] }}:9558']
183205 labels:
184206 instance: "{{ item }}"
185207 project: "{{ prometheus_project }}"
186208{% endfor %}
187-
209+ {% endif %}
188210 - job_name: "nvidia_gpu_exporter"
189211 metric_relabel_configs:
190212 - action: drop
@@ -194,13 +216,19 @@ scrape_configs:
194216 format: ['prometheus']
195217 metrics_path: /metrics
196218 static_configs:
197- {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project %}
219+ {% if hostvars [inventory_hostname ].nomad_mode == 'single' %}
220+ - targets: ['127.0.0.1:9835']
221+ labels:
222+ instance: "{{ inventory_hostname }}"
223+ project: "{{ prometheus_project }}"
224+ {% elif hostvars [inventory_hostname ].nomad_mode == 'cluster' %}
225+ {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project and item != inventory_hostname %}
198226 - targets: ['{{ hostvars[item] ['ansible_' + hostvars[item] .nomad_iface] ['ipv4'] ['address'] }}:9835']
199227 labels:
200228 instance: "{{ item }}"
201229 project: "{{ prometheus_project }}"
202230{% endfor %}
203-
231+ {% endif %}
204232 - job_name: "nomad_exporter"
205233 metric_relabel_configs:
206234 - action: drop
@@ -214,13 +242,19 @@ scrape_configs:
214242 tls_config:
215243 insecure_skip_verify: true
216244 static_configs:
217- {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project %}
245+ {% if hostvars [inventory_hostname ].nomad_mode == 'single' %}
246+ - targets: ['127.0.0.1:4646']
247+ labels:
248+ instance: "{{ inventory_hostname }}"
249+ project: "{{ prometheus_project }}"
250+ {% elif hostvars [inventory_hostname ].nomad_mode == 'cluster' %}
251+ {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project and item != inventory_hostname %}
218252 - targets: ['{{ hostvars[item] ['ansible_' + hostvars[item] .nomad_iface] ['ipv4'] ['address'] }}:4646']
219253 labels:
220254 instance: "{{ item }}"
221255 project: "{{ prometheus_project }}"
222256{% endfor %}
223-
257+ {% endif %}
224258 - job_name: 'mimir_exporter'
225259 nomad_sd_configs:
226260 - server: "https://{{ nomad_primary_master_address | default(hostvars[inventory_hostname] ['ansible_' + hostvars[inventory_hostname] .nomad_iface] ['ipv4'] ['address'] ) }}:4646"
@@ -246,16 +280,22 @@ scrape_configs:
246280 tls_config:
247281 insecure_skip_verify: true
248282 static_configs:
249- {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project %}
283+ {% if hostvars [inventory_hostname ].nomad_mode == 'single' %}
284+ - targets: ['127.0.0.1:9080']
285+ labels:
286+ instance: "{{ inventory_hostname }}"
287+ project: "{{ prometheus_project }}"
288+ {% elif hostvars [inventory_hostname ].nomad_mode == 'cluster' %}
289+ {% for item in groups ['infrastructure' ] | default ([]) if item .split ('.' )[4] == prometheus_project and item != inventory_hostname %}
250290 - targets: ['{{ hostvars[item] ['ansible_' + hostvars[item] .nomad_iface] ['ipv4'] ['address'] }}:9080']
251291 labels:
252292 instance: "{{ item }}"
253293 project: "{{ prometheus_project }}"
254294{% endfor %}
255-
295+ {% endif %}
256296 - job_name: 'blackbox'
257297 static_configs:
258- - targets: ['127.0.0.1:9115']
298+ - targets: ['{% if hostvars [ inventory_hostname ]. nomad_mode == 'single' %} 127.0.0.1{% else %} {{ hostvars[inventory_hostnam e] ['ansible_' + nomad_ifac e] ['ipv4 '] ['address '] }} {% endif %} :9115']
259299 labels:
260300 instance: "{{ inventory_hostname }}"
261301 project: "{{ prometheus_project }}"
0 commit comments