Skip to content

Commit 112edb8

Browse files
dougszumskiosfrickler
authored andcommitted
Add support for deploying Prometheus libvirt exporter
Add support for deploying the Kolla Prometheus libvirt exporter image to facilitate gathering metrics from the Nova libvirt service. Changes for backport: - set default for enable_prometheus_libvirt_exporter to "no" - don't fail if the new group isn't defined Co-Authored-by: Dr. Jens Harbott <[email protected]> Change-Id: Ib27e60c39297b86ae674297370f9543ab08cda05 Partially-Implements: blueprint libvirt-exporter (cherry picked from commit 491d418) (cherry picked from commit 7259672)
1 parent 1714bc0 commit 112edb8

File tree

13 files changed

+83
-1
lines changed

13 files changed

+83
-1
lines changed

ansible/group_vars/all.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ prometheus_rabbitmq_exporter_port: "{{ rabbitmq_prometheus_port }}"
463463
# Default cadvisor port of 8080 already in use
464464
prometheus_cadvisor_port: "18080"
465465
prometheus_fluentd_integration_port: "24231"
466+
prometheus_libvirt_exporter_port: "9177"
466467

467468
# Prometheus alertmanager ports
468469
prometheus_alertmanager_port: "9093"
@@ -1125,6 +1126,7 @@ enable_prometheus_openstack_exporter: "{{ enable_prometheus | bool }}"
11251126
enable_prometheus_elasticsearch_exporter: "{{ enable_prometheus | bool and enable_elasticsearch | bool }}"
11261127
enable_prometheus_blackbox_exporter: "{{ enable_prometheus | bool }}"
11271128
enable_prometheus_rabbitmq_exporter: "{{ enable_prometheus | bool and enable_rabbitmq | bool }}"
1129+
enable_prometheus_libvirt_exporter: "no"
11281130

11291131
prometheus_alertmanager_user: "admin"
11301132
prometheus_openstack_exporter_interval: "60s"
@@ -1133,6 +1135,7 @@ prometheus_elasticsearch_exporter_interval: "60s"
11331135
prometheus_cmdline_extras:
11341136
prometheus_ceph_mgr_exporter_endpoints: []
11351137
prometheus_openstack_exporter_endpoint_type: "internal"
1138+
prometheus_libvirt_exporter_interval: "60s"
11361139

11371140
############
11381141
# Vitrage

ansible/inventory/all-in-one

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ elasticsearch
729729
[prometheus-blackbox-exporter:children]
730730
monitoring
731731

732+
[prometheus-libvirt-exporter:children]
733+
compute
734+
732735
[masakari-api:children]
733736
control
734737

ansible/inventory/multinode

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ elasticsearch
747747
[prometheus-blackbox-exporter:children]
748748
monitoring
749749

750+
[prometheus-libvirt-exporter:children]
751+
compute
752+
750753
[masakari-api:children]
751754
control
752755

ansible/roles/prometheus/defaults/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ prometheus_services:
9292
image: "{{ prometheus_blackbox_exporter_image_full }}"
9393
volumes: "{{ prometheus_blackbox_exporter_default_volumes + prometheus_blackbox_exporter_extra_volumes }}"
9494
dimensions: "{{ prometheus_blackbox_exporter_dimensions }}"
95+
prometheus-libvirt-exporter:
96+
container_name: "prometheus_libvirt_exporter"
97+
group: "prometheus-libvirt-exporter"
98+
enabled: "{{ enable_prometheus_libvirt_exporter | bool }}"
99+
image: "{{ prometheus_libvirt_exporter_image_full }}"
100+
volumes: "{{ prometheus_libvirt_exporter_default_volumes + prometheus_libvirt_exporter_extra_volumes }}"
101+
dimensions: "{{ prometheus_libvirt_exporter_dimensions }}"
95102

96103
####################
97104
# Database
@@ -166,6 +173,10 @@ prometheus_blackbox_exporter_image: "{{ docker_registry ~ '/' if docker_registry
166173
prometheus_blackbox_exporter_tag: "{{ prometheus_tag }}"
167174
prometheus_blackbox_exporter_image_full: "{{ prometheus_blackbox_exporter_image }}:{{ prometheus_blackbox_exporter_tag }}"
168175

176+
prometheus_libvirt_exporter_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ prometheus_install_type }}-prometheus-libvirt-exporter"
177+
prometheus_libvirt_exporter_tag: "{{ prometheus_tag }}"
178+
prometheus_libvirt_exporter_image_full: "{{ prometheus_libvirt_exporter_image }}:{{ prometheus_libvirt_exporter_tag }}"
179+
169180
prometheus_server_dimensions: "{{ default_container_dimensions }}"
170181
prometheus_haproxy_exporter_dimensions: "{{ default_container_dimensions }}"
171182
prometheus_mysqld_exporter_dimensions: "{{ default_container_dimensions }}"
@@ -176,6 +187,7 @@ prometheus_alertmanager_dimensions: "{{ default_container_dimensions }}"
176187
prometheus_openstack_exporter_dimensions: "{{ default_container_dimensions }}"
177188
prometheus_elasticsearch_exporter_dimensions: "{{ default_container_dimensions }}"
178189
prometheus_blackbox_exporter_dimensions: "{{ default_container_dimensions }}"
190+
prometheus_libvirt_exporter_dimensions: "{{ default_container_dimensions }}"
179191

180192
prometheus_server_default_volumes:
181193
- "{{ node_config_directory }}/prometheus-server/:{{ container_config_directory }}/:ro"
@@ -236,6 +248,11 @@ prometheus_blackbox_exporter_default_volumes:
236248
- "/etc/localtime:/etc/localtime:ro"
237249
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
238250
- "kolla_logs:/var/log/kolla/"
251+
prometheus_libvirt_exporter_default_volumes:
252+
- "{{ node_config_directory }}/prometheus-libvirt-exporter/:{{ container_config_directory }}/:ro"
253+
- "/etc/localtime:/etc/localtime:ro"
254+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
255+
- "/run/libvirt:/run/libvirt:ro"
239256

240257
prometheus_extra_volumes: "{{ default_extra_volumes }}"
241258
prometheus_server_extra_volumes: "{{ prometheus_extra_volumes }}"
@@ -248,6 +265,7 @@ prometheus_alertmanager_extra_volumes: "{{ prometheus_extra_volumes }}"
248265
prometheus_openstack_exporter_extra_volumes: "{{ prometheus_extra_volumes }}"
249266
prometheus_elasticsearch_exporter_extra_volumes: "{{ prometheus_extra_volumes }}"
250267
prometheus_blackbox_exporter_extra_volumes: "{{ prometheus_extra_volumes }}"
268+
prometheus_libvirt_exporter_extra_volumes: "{{ prometheus_extra_volumes }}"
251269

252270
prometheus_openstack_exporter_disabled_volume: "{{ '--disable-service.volume' if not enable_cinder | bool else '' }}"
253271
prometheus_openstack_exporter_disabled_dns: "{{ '--disable-service.dns' if not enable_designate | bool else '' }}"

ansible/roles/prometheus/handlers/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,18 @@
149149
dimensions: "{{ service.dimensions }}"
150150
when:
151151
- kolla_action != "config"
152+
153+
- name: Restart prometheus-libvirt-exporter container
154+
vars:
155+
service_name: "prometheus-libvirt-exporter"
156+
service: "{{ prometheus_services[service_name] }}"
157+
become: true
158+
kolla_docker:
159+
action: "recreate_or_restart_container"
160+
common_options: "{{ docker_common_options }}"
161+
name: "{{ service.container_name }}"
162+
image: "{{ service.image }}"
163+
volumes: "{{ service.volumes }}"
164+
dimensions: "{{ service.dimensions }}"
165+
when:
166+
- kolla_action != "config"

ansible/roles/prometheus/tasks/check-containers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
volumes: "{{ item.value.volumes }}"
1111
dimensions: "{{ item.value.dimensions }}"
1212
when:
13-
- inventory_hostname in groups[item.value.group]
13+
- inventory_hostname in groups.get(item.value.group, [])
1414
- item.value.enabled | bool
1515
with_dict: "{{ prometheus_services }}"
1616
notify:

ansible/roles/prometheus/tasks/precheck.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- prometheus_openstack_exporter
2020
- prometheus_elasticsearch_exporter
2121
- prometheus_blackbox_exporter
22+
- prometheus_libvirt_exporter
2223
register: container_facts
2324

2425
- name: Checking free port for Prometheus server
@@ -149,3 +150,17 @@
149150
- enable_prometheus_blackbox_exporter | bool
150151
with_items:
151152
- "{{ prometheus_blackbox_exporter_port }}"
153+
154+
- name: Checking free ports for Prometheus libvirt-exporter
155+
wait_for:
156+
host: "{{ 'api' | kolla_address }}"
157+
port: "{{ item }}"
158+
connect_timeout: 1
159+
timeout: 1
160+
state: stopped
161+
when:
162+
- container_facts['prometheus_libvirt_exporter'] is not defined
163+
- inventory_hostname in groups.get('prometheus-libvirt-exporter', [])
164+
- enable_prometheus_libvirt_exporter | bool
165+
with_items:
166+
- "{{ prometheus_libvirt_exporter_port }}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"command": "/opt/libvirt-exporter --web.listen-address={{ api_interface_address }}:{{ prometheus_libvirt_exporter_port }}",
3+
"config_files": []
4+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ scrape_configs:
145145
replacement: '{{ api_interface_address | put_address_in_context('url') }}:{{ prometheus_blackbox_exporter_port }}'
146146
{% endif %}
147147

148+
{% if enable_prometheus_libvirt_exporter | bool %}
149+
- job_name: libvirt_exporter
150+
scrape_interval: {{ prometheus_libvirt_exporter_interval }}
151+
honor_labels: true
152+
static_configs:
153+
- targets:
154+
{% for host in groups["prometheus-libvirt-exporter"] %}
155+
- '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_libvirt_exporter_port'] }}'
156+
{% endfor %}
157+
{% endif %}
158+
148159
{% if enable_prometheus_alertmanager | bool %}
149160
alerting:
150161
alertmanagers:

ansible/site.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@
454454
- prometheus-openstack-exporter
455455
- prometheus-elasticsearch-exporter
456456
- prometheus-blackbox-exporter
457+
- prometheus-libvirt-exporter
457458
- '&enable_prometheus_True'
458459
serial: '{{ kolla_serial|default("0") }}'
459460
roles:

0 commit comments

Comments
 (0)