Skip to content

Commit 2fd8a37

Browse files
committed
Use friendly Prometheus target names
Backport of Change-Id: I16fdb2f93ddb656eeacd3f2b84190f9bdcfaa21c
1 parent f8eaa5b commit 2fd8a37

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

ansible/roles/prometheus/templates/prometheus.yml.j2

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,89 @@ scrape_configs:
1717
static_configs:
1818
- targets:
1919
{% for host in groups['prometheus'] %}
20-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ prometheus_port }}'
20+
- '{{ host }}:{{ prometheus_port }}'
2121
{% endfor %}
22+
relabel_configs:
23+
- source_labels: [__address__]
24+
regex: "([^:]+):\\d+"
25+
target_label: instance
2226

2327
{% if enable_prometheus_node_exporter | bool %}
2428
- job_name: node
2529
static_configs:
2630
- targets:
2731
{% for host in groups['prometheus-node-exporter'] %}
28-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_node_exporter_port'] }}'
32+
- '{{ host }}:{{ hostvars[host]['prometheus_node_exporter_port'] }}'
2933
{% endfor %}
34+
relabel_configs:
35+
- source_labels: [__address__]
36+
regex: "([^:]+):\\d+"
37+
target_label: instance
3038
{% endif %}
3139

3240
{% if enable_prometheus_mysqld_exporter | bool %}
3341
- job_name: mysqld
3442
static_configs:
3543
- targets:
3644
{% for host in groups['prometheus-mysqld-exporter'] %}
37-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_mysqld_exporter_port'] }}'
45+
- '{{ host }}:{{ hostvars[host]['prometheus_mysqld_exporter_port'] }}'
3846
{% endfor %}
47+
relabel_configs:
48+
- source_labels: [__address__]
49+
regex: "([^:]+):\\d+"
50+
target_label: instance
3951
{% endif %}
4052

4153
{% if enable_prometheus_haproxy_exporter | bool %}
4254
- job_name: haproxy
4355
static_configs:
4456
- targets:
4557
{% for host in groups['prometheus-haproxy-exporter'] %}
46-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_haproxy_exporter_port'] }}'
58+
- '{{ host }}:{{ hostvars[host]['prometheus_haproxy_exporter_port'] }}'
4759
{% endfor %}
60+
relabel_configs:
61+
- source_labels: [__address__]
62+
regex: "([^:]+):\\d+"
63+
target_label: instance
4864
{% endif %}
4965

5066
{% if enable_prometheus_rabbitmq_exporter | bool %}
5167
- job_name: rabbitmq
5268
static_configs:
5369
- targets:
5470
{% for host in groups['rabbitmq'] %}
55-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_rabbitmq_exporter_port'] }}'
71+
- '{{ host }}:{{ hostvars[host]['prometheus_rabbitmq_exporter_port'] }}'
5672
{% endfor %}
73+
relabel_configs:
74+
- source_labels: [__address__]
75+
regex: "([^:]+):\\d+"
76+
target_label: instance
5777
{% endif %}
5878

5979
{% if enable_prometheus_memcached_exporter | bool %}
6080
- job_name: memcached
6181
static_configs:
6282
- targets:
6383
{% for host in groups['prometheus-memcached-exporter'] %}
64-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_memcached_exporter_port'] }}'
84+
- '{{ host }}:{{ hostvars[host]['prometheus_memcached_exporter_port'] }}'
6585
{% endfor %}
86+
relabel_configs:
87+
- source_labels: [__address__]
88+
regex: "([^:]+):\\d+"
89+
target_label: instance
6690
{% endif %}
6791

6892
{% if enable_prometheus_cadvisor | bool %}
6993
- job_name: cadvisor
7094
static_configs:
7195
- targets:
7296
{% for host in groups["prometheus-cadvisor"] %}
73-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_cadvisor_port'] }}'
97+
- '{{ host }}:{{ hostvars[host]['prometheus_cadvisor_port'] }}'
7498
{% endfor %}
99+
relabel_configs:
100+
- source_labels: [__address__]
101+
regex: "([^:]+):\\d+"
102+
target_label: instance
75103
{% endif %}
76104

77105
{% if enable_prometheus_ceph_mgr_exporter | bool %}
@@ -82,6 +110,10 @@ scrape_configs:
82110
{% for exporter in prometheus_ceph_mgr_exporter_endpoints %}
83111
- '{{ exporter }}'
84112
{% endfor %}
113+
relabel_configs:
114+
- source_labels: [__address__]
115+
regex: "([^:]+):\\d+"
116+
target_label: instance
85117
{% endif %}
86118

87119
{% if enable_prometheus_openstack_exporter | bool %}
@@ -92,8 +124,12 @@ scrape_configs:
92124
static_configs:
93125
- targets:
94126
{% for host in groups["prometheus-openstack-exporter"] %}
95-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_openstack_exporter_port'] }}'
127+
- '{{ host }}:{{ hostvars[host]['prometheus_openstack_exporter_port'] }}'
96128
{% endfor %}
129+
relabel_configs:
130+
- source_labels: [__address__]
131+
regex: "([^:]+):\\d+"
132+
target_label: instance
97133
{% endif %}
98134

99135
{% if enable_prometheus_elasticsearch_exporter | bool %}
@@ -102,8 +138,12 @@ scrape_configs:
102138
static_configs:
103139
- targets:
104140
{% for host in groups["prometheus-elasticsearch-exporter"] %}
105-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_elasticsearch_exporter_port'] }}'
141+
- '{{ host }}:{{ hostvars[host]['prometheus_elasticsearch_exporter_port'] }}'
106142
{% endfor %}
143+
relabel_configs:
144+
- source_labels: [__address__]
145+
regex: "([^:]+):\\d+"
146+
target_label: instance
107147
{% endif %}
108148

109149
{% if enable_prometheus_blackbox_exporter | bool and prometheus_blackbox_exporter_endpoints | length > 0 | bool %}
@@ -141,14 +181,18 @@ scrape_configs:
141181
static_configs:
142182
- targets:
143183
{% for host in groups['prometheus-alertmanager'] %}
144-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
184+
- '{{ host }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
145185
{% endfor %}
186+
relabel_configs:
187+
- source_labels: [__address__]
188+
regex: "([^:]+):\\d+"
189+
target_label: instance
146190

147191
alerting:
148192
alertmanagers:
149193
- static_configs:
150194
- targets:
151195
{% for host in groups["prometheus-alertmanager"] %}
152-
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
196+
- '{{ host }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
153197
{% endfor %}
154198
{% endif %}

0 commit comments

Comments
 (0)