Merge "Use friendly target names in Prometheus"

This commit is contained in:
Zuul 2021-10-06 16:27:21 +00:00 committed by Gerrit Code Review
commit 01470fc7e9
2 changed files with 73 additions and 12 deletions

View File

@ -17,16 +17,24 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups['prometheus'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ prometheus_port }}'
- '{{ host }}:{{ prometheus_port }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% if enable_prometheus_node_exporter | bool %}
- job_name: node
static_configs:
- targets:
{% for host in groups['prometheus-node-exporter'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_node_exporter_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_node_exporter_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_mysqld_exporter | bool %}
@ -34,8 +42,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups['prometheus-mysqld-exporter'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_mysqld_exporter_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_mysqld_exporter_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_haproxy_exporter | bool %}
@ -43,8 +55,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups['prometheus-haproxy-exporter'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_haproxy_exporter_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_haproxy_exporter_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_rabbitmq_exporter | bool %}
@ -52,8 +68,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups['rabbitmq'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_rabbitmq_exporter_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_rabbitmq_exporter_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_memcached_exporter | bool %}
@ -61,8 +81,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups['prometheus-memcached-exporter'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_memcached_exporter_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_memcached_exporter_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_cadvisor | bool %}
@ -70,8 +94,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups["prometheus-cadvisor"] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_cadvisor_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_cadvisor_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_fluentd_integration | bool %}
@ -79,8 +107,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups['fluentd'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_fluentd_integration_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_fluentd_integration_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_ceph_mgr_exporter | bool %}
@ -91,6 +123,10 @@ scrape_configs:
{% for exporter in prometheus_ceph_mgr_exporter_endpoints %}
- '{{ exporter }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_openstack_exporter | bool %}
@ -101,8 +137,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups["prometheus-openstack-exporter"] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_openstack_exporter_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_openstack_exporter_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_elasticsearch_exporter | bool %}
@ -111,8 +151,12 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups["prometheus-elasticsearch-exporter"] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_elasticsearch_exporter_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_elasticsearch_exporter_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
{% endif %}
{% if enable_prometheus_blackbox_exporter | bool and prometheus_blackbox_exporter_endpoints | length > 0 | bool %}
@ -150,14 +194,18 @@ scrape_configs:
static_configs:
- targets:
{% for host in groups['prometheus-alertmanager'] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
{% endfor %}
relabel_configs:
- source_labels: [__address__]
regex: "([^:]+):\\d+"
target_label: instance
alerting:
alertmanagers:
- static_configs:
- targets:
{% for host in groups["prometheus-alertmanager"] %}
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
- '{{ host }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}'
{% endfor %}
{% endif %}

View File

@ -0,0 +1,13 @@
---
features:
- |
Changes target names in Prometheus to user-friendly, Ansible inventory
based values.
upgrade:
- |
Changes Prometheus targets naming. This makes their names more user
friendly but also creates a completely new set of a time series data.
New target names are taken from Ansible inventory and have the exporter
port number stripped off. Any Grafana dashboard that relies on a specific,
hard-coded naming pattern for the targets will stop showing metrics after
the upgrade.