diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index c4dac983a9..9ae208b976 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -452,6 +452,7 @@ prometheus_rabbitmq_exporter_port: "15692" # Default cadvisor port of 8080 already in use prometheus_cadvisor_port: "18080" prometheus_fluentd_integration_port: "24231" +prometheus_libvirt_exporter_port: "9177" # Prometheus alertmanager ports prometheus_alertmanager_port: "9093" @@ -1102,6 +1103,7 @@ enable_prometheus_openstack_exporter: "{{ enable_prometheus | bool }}" enable_prometheus_elasticsearch_exporter: "{{ enable_prometheus | bool and enable_elasticsearch | bool }}" enable_prometheus_blackbox_exporter: "{{ enable_prometheus | bool }}" enable_prometheus_rabbitmq_exporter: "{{ enable_prometheus | bool and enable_rabbitmq | bool }}" +enable_prometheus_libvirt_exporter: "{{ enable_prometheus | bool and enable_nova | bool and nova_compute_virt_type in ['kvm', 'qemu'] }}" prometheus_alertmanager_user: "admin" prometheus_openstack_exporter_interval: "60s" @@ -1110,6 +1112,7 @@ prometheus_elasticsearch_exporter_interval: "60s" prometheus_cmdline_extras: prometheus_ceph_mgr_exporter_endpoints: [] prometheus_openstack_exporter_endpoint_type: "internal" +prometheus_libvirt_exporter_interval: "60s" ############ # Vitrage diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one index 42f903b08c..aeee2133bd 100644 --- a/ansible/inventory/all-in-one +++ b/ansible/inventory/all-in-one @@ -699,6 +699,9 @@ elasticsearch [prometheus-blackbox-exporter:children] monitoring +[prometheus-libvirt-exporter:children] +compute + [masakari-api:children] control diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode index 24de4a233c..1ca91a8370 100644 --- a/ansible/inventory/multinode +++ b/ansible/inventory/multinode @@ -717,6 +717,9 @@ elasticsearch [prometheus-blackbox-exporter:children] monitoring +[prometheus-libvirt-exporter:children] +compute + [masakari-api:children] control diff --git a/ansible/roles/prometheus/defaults/main.yml b/ansible/roles/prometheus/defaults/main.yml index 455684d531..0afc004817 100644 --- a/ansible/roles/prometheus/defaults/main.yml +++ b/ansible/roles/prometheus/defaults/main.yml @@ -94,6 +94,13 @@ prometheus_services: image: "{{ prometheus_blackbox_exporter_image_full }}" volumes: "{{ prometheus_blackbox_exporter_default_volumes + prometheus_blackbox_exporter_extra_volumes }}" dimensions: "{{ prometheus_blackbox_exporter_dimensions }}" + prometheus-libvirt-exporter: + container_name: "prometheus_libvirt_exporter" + group: "prometheus-libvirt-exporter" + enabled: "{{ enable_prometheus_libvirt_exporter | bool }}" + image: "{{ prometheus_libvirt_exporter_image_full }}" + volumes: "{{ prometheus_libvirt_exporter_default_volumes + prometheus_libvirt_exporter_extra_volumes }}" + dimensions: "{{ prometheus_libvirt_exporter_dimensions }}" #################### # Database @@ -160,6 +167,10 @@ prometheus_blackbox_exporter_image: "{{ docker_registry ~ '/' if docker_registry prometheus_blackbox_exporter_tag: "{{ prometheus_tag }}" prometheus_blackbox_exporter_image_full: "{{ prometheus_blackbox_exporter_image }}:{{ prometheus_blackbox_exporter_tag }}" +prometheus_libvirt_exporter_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ prometheus_install_type }}-prometheus-libvirt-exporter" +prometheus_libvirt_exporter_tag: "{{ prometheus_tag }}" +prometheus_libvirt_exporter_image_full: "{{ prometheus_libvirt_exporter_image }}:{{ prometheus_libvirt_exporter_tag }}" + prometheus_server_dimensions: "{{ default_container_dimensions }}" prometheus_haproxy_exporter_dimensions: "{{ default_container_dimensions }}" prometheus_mysqld_exporter_dimensions: "{{ default_container_dimensions }}" @@ -170,6 +181,7 @@ prometheus_alertmanager_dimensions: "{{ default_container_dimensions }}" prometheus_openstack_exporter_dimensions: "{{ default_container_dimensions }}" prometheus_elasticsearch_exporter_dimensions: "{{ default_container_dimensions }}" prometheus_blackbox_exporter_dimensions: "{{ default_container_dimensions }}" +prometheus_libvirt_exporter_dimensions: "{{ default_container_dimensions }}" prometheus_server_default_volumes: - "{{ node_config_directory }}/prometheus-server/:{{ container_config_directory }}/:ro" @@ -231,6 +243,11 @@ prometheus_blackbox_exporter_default_volumes: - "/etc/localtime:/etc/localtime:ro" - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}" - "kolla_logs:/var/log/kolla/" +prometheus_libvirt_exporter_default_volumes: + - "{{ node_config_directory }}/prometheus-libvirt-exporter/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}" + - "/run/libvirt:/run/libvirt:ro" prometheus_extra_volumes: "{{ default_extra_volumes }}" prometheus_server_extra_volumes: "{{ prometheus_extra_volumes }}" @@ -243,6 +260,7 @@ prometheus_alertmanager_extra_volumes: "{{ prometheus_extra_volumes }}" prometheus_openstack_exporter_extra_volumes: "{{ prometheus_extra_volumes }}" prometheus_elasticsearch_exporter_extra_volumes: "{{ prometheus_extra_volumes }}" prometheus_blackbox_exporter_extra_volumes: "{{ prometheus_extra_volumes }}" +prometheus_libvirt_exporter_extra_volumes: "{{ prometheus_extra_volumes }}" prometheus_openstack_exporter_disabled_volume: "{{ '--disable-service.volume' if not enable_cinder | bool else '' }}" prometheus_openstack_exporter_disabled_dns: "{{ '--disable-service.dns' if not enable_designate | bool else '' }}" diff --git a/ansible/roles/prometheus/handlers/main.yml b/ansible/roles/prometheus/handlers/main.yml index 42820e6365..d155cf825c 100644 --- a/ansible/roles/prometheus/handlers/main.yml +++ b/ansible/roles/prometheus/handlers/main.yml @@ -149,3 +149,18 @@ dimensions: "{{ service.dimensions }}" when: - kolla_action != "config" + +- name: Restart prometheus-libvirt-exporter container + vars: + service_name: "prometheus-libvirt-exporter" + service: "{{ prometheus_services[service_name] }}" + become: true + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + dimensions: "{{ service.dimensions }}" + when: + - kolla_action != "config" diff --git a/ansible/roles/prometheus/tasks/precheck.yml b/ansible/roles/prometheus/tasks/precheck.yml index c3aa2eadde..cc734eb0ba 100644 --- a/ansible/roles/prometheus/tasks/precheck.yml +++ b/ansible/roles/prometheus/tasks/precheck.yml @@ -19,6 +19,7 @@ - prometheus_openstack_exporter - prometheus_elasticsearch_exporter - prometheus_blackbox_exporter + - prometheus_libvirt_exporter register: container_facts - name: Checking free port for Prometheus server @@ -149,3 +150,17 @@ - enable_prometheus_blackbox_exporter | bool with_items: - "{{ prometheus_blackbox_exporter_port }}" + +- name: Checking free ports for Prometheus libvirt-exporter + wait_for: + host: "{{ 'api' | kolla_address }}" + port: "{{ item }}" + connect_timeout: 1 + timeout: 1 + state: stopped + when: + - container_facts['prometheus_libvirt_exporter'] is not defined + - inventory_hostname in groups['prometheus-libvirt-exporter'] + - enable_prometheus_libvirt_exporter | bool + with_items: + - "{{ prometheus_libvirt_exporter_port }}" diff --git a/ansible/roles/prometheus/templates/prometheus-libvirt-exporter.json.j2 b/ansible/roles/prometheus/templates/prometheus-libvirt-exporter.json.j2 new file mode 100644 index 0000000000..518358d8b1 --- /dev/null +++ b/ansible/roles/prometheus/templates/prometheus-libvirt-exporter.json.j2 @@ -0,0 +1,4 @@ +{ + "command": "/opt/libvirt-exporter --web.listen-address={{ api_interface_address }}:{{ prometheus_libvirt_exporter_port }}", + "config_files": [] +} diff --git a/ansible/roles/prometheus/templates/prometheus.yml.j2 b/ansible/roles/prometheus/templates/prometheus.yml.j2 index 1e829648ac..f6a9c03e1f 100644 --- a/ansible/roles/prometheus/templates/prometheus.yml.j2 +++ b/ansible/roles/prometheus/templates/prometheus.yml.j2 @@ -189,6 +189,17 @@ scrape_configs: replacement: '{{ api_interface_address | put_address_in_context('url') }}:{{ prometheus_blackbox_exporter_port }}' {% endif %} +{% if enable_prometheus_libvirt_exporter | bool %} + - job_name: libvirt_exporter + scrape_interval: {{ prometheus_libvirt_exporter_interval }} + honor_labels: true + static_configs: + - targets: +{% for host in groups["prometheus-libvirt-exporter"] %} + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_libvirt_exporter_port'] }}' +{% endfor %} +{% endif %} + {% if enable_prometheus_alertmanager | bool %} - job_name: alertmanager static_configs: diff --git a/ansible/site.yml b/ansible/site.yml index d6f1786eeb..bc31f22c1e 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -434,6 +434,7 @@ - prometheus-openstack-exporter - prometheus-elasticsearch-exporter - prometheus-blackbox-exporter + - prometheus-libvirt-exporter - '&enable_prometheus_True' serial: '{{ kolla_serial|default("0") }}' roles: diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml index 1b409ae35d..bec5973a00 100644 --- a/etc/kolla/globals.yml +++ b/etc/kolla/globals.yml @@ -707,6 +707,7 @@ #enable_prometheus_openstack_exporter: "{{ enable_prometheus | bool }}" #enable_prometheus_elasticsearch_exporter: "{{ enable_prometheus | bool and enable_elasticsearch | bool }}" #enable_prometheus_blackbox_exporter: "{{ enable_prometheus | bool }}" +#enable_prometheus_libvirt_exporter: "{{ enable_prometheus | bool and enable_nova | bool and nova_compute_virt_type in ['kvm', 'qemu'] }}" # List of extra parameters passed to prometheus. You can add as many to the list. #prometheus_cmdline_extras: diff --git a/releasenotes/notes/add-prometheus-libvirt-exporter-b05a3a9c08db517c.yaml b/releasenotes/notes/add-prometheus-libvirt-exporter-b05a3a9c08db517c.yaml new file mode 100644 index 0000000000..9e32d6e4b7 --- /dev/null +++ b/releasenotes/notes/add-prometheus-libvirt-exporter-b05a3a9c08db517c.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Deploys and configures a prometheus-libvirt-exporter image as part of the + Prometheus monitoring stack. diff --git a/tests/templates/inventory.j2 b/tests/templates/inventory.j2 index bea292a621..b6b6bcd559 100644 --- a/tests/templates/inventory.j2 +++ b/tests/templates/inventory.j2 @@ -770,6 +770,9 @@ elasticsearch [prometheus-blackbox-exporter:children] monitoring +[prometheus-libvirt-exporter:children] +compute + # NOTE(yoctozepto): In CI we want to test Masakari HA but not of other services, # to conserve the resources. Hence, we set Masakari groups to use both # primary and secondary while the parent group (control) uses only primary.