diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index ae8111dce5..962df54055 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -273,6 +273,8 @@ prometheus_node_exporter_port: "9100" prometheus_mysqld_exporter_port: "9104" prometheus_haproxy_exporter_port: "9101" prometheus_memcached_exporter_port: "9150" +# Default cadvisor port of 8080 already in use +prometheus_cadvisor_port: "18080" qdrouterd_port: "31459" @@ -803,3 +805,4 @@ enable_prometheus_haproxy_exporter: "{{ enable_haproxy | bool }}" enable_prometheus_mysqld_exporter: "{{ enable_mariadb | bool }}" enable_prometheus_node_exporter: "yes" enable_prometheus_memcached_exporter: "{{ enable_memcached | bool }}" +enable_prometheus_cadvisor: "yes" diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one index 1e11824aae..25cc18a74c 100644 --- a/ansible/inventory/all-in-one +++ b/ansible/inventory/all-in-one @@ -671,3 +671,10 @@ haproxy [prometheus-memcached-exporter:children] memcached + +[prometheus-cadvisor:children] +monitoring +control +compute +network +storage diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode index 2fd60ec6aa..1f9c9ecedd 100644 --- a/ansible/inventory/multinode +++ b/ansible/inventory/multinode @@ -690,3 +690,10 @@ haproxy [prometheus-memcached-exporter:children] memcached + +[prometheus-cadvisor:children] +monitoring +control +compute +network +storage diff --git a/ansible/roles/prometheus/defaults/main.yml b/ansible/roles/prometheus/defaults/main.yml index a423a67537..2c6db50537 100644 --- a/ansible/roles/prometheus/defaults/main.yml +++ b/ansible/roles/prometheus/defaults/main.yml @@ -52,6 +52,20 @@ prometheus_services: - "{{ node_config_directory }}/prometheus-memcached-exporter/:{{ container_config_directory }}/:ro" - "/etc/localtime:/etc/localtime:ro" - "kolla_logs:/var/log/kolla/" + prometheus-cadvisor: + container_name: "prometheus_cadvisor" + group: "prometheus-cadvisor" + enabled: "{{ enable_prometheus_cadvisor | bool }}" + image: "{{ prometheus_cadvisor_image_full }}" + volumes: + - "{{ node_config_directory }}/prometheus-cadvisor/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + - "/:/rootfs:ro" + - "/var/run:/var/run:rw" + - "/sys:/sys:ro" + - "/varlib/docker/:/var/lib/docker:ro" + - "/dev/disk/:/dev/disk:ro" #################### # Database @@ -83,3 +97,7 @@ prometheus_node_exporter_image_full: "{{ prometheus_node_exporter_image }}:{{ pr prometheus_memcached_exporter_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ prometheus_install_type }}-prometheus-memcached-exporter" prometheus_memcached_exporter_tag: "{{ prometheus_tag }}" prometheus_memcached_exporter_image_full: "{{ prometheus_memcached_exporter_image }}:{{ prometheus_memcached_exporter_tag }}" + +prometheus_cadvisor_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-prometheus-cadvisor" +prometheus_cadvisor_tag: "{{ openstack_release }}" +prometheus_cadvisor_image_full: "{{ prometheus_cadvisor_image }}:{{ prometheus_cadvisor_tag }}" diff --git a/ansible/roles/prometheus/handlers/main.yml b/ansible/roles/prometheus/handlers/main.yml index 93dbfa170a..7f8134fa79 100644 --- a/ansible/roles/prometheus/handlers/main.yml +++ b/ansible/roles/prometheus/handlers/main.yml @@ -96,3 +96,22 @@ - service.enabled | bool - config_json.changed | bool or prometheus_container.changed | bool + +- name: Restart prometheus-cadvisor container + vars: + service_name: "prometheus-cadvisor" + service: "{{ prometheus_services[service_name] }}" + config_json: "{{ prometheus_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + prometheus_container: "{{ check_prometheus_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + when: + - kolla_action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or prometheus_container.changed | bool diff --git a/ansible/roles/prometheus/tasks/precheck.yml b/ansible/roles/prometheus/tasks/precheck.yml index 804cffdb8c..1a76cd9b66 100644 --- a/ansible/roles/prometheus/tasks/precheck.yml +++ b/ansible/roles/prometheus/tasks/precheck.yml @@ -6,6 +6,7 @@ - prometheus_node_exporter - prometheus_haproxy_exporter - prometheus_mysqld_exporter + - prometheus_cadvisor register: container_facts - name: Checking free port for Prometheus server @@ -66,3 +67,15 @@ - container_facts['prometheus_memcached_exporter'] is not defined - inventory_hostname in groups['prometheus-memcached-exporter'] - enable_prometheus_memcached_exporter | bool + +- name: Checking free port for Prometheus cAdvisor + wait_for: + host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" + port: "{{ prometheus_cadvisor_port }}" + connect_timeout: 1 + timeout: 1 + state: stopped + when: + - container_facts['prometheus_cadvisor'] is not defined + - inventory_hostname in groups['prometheus-cadvisor'] + - enable_prometheus_cadvisor | bool diff --git a/ansible/roles/prometheus/templates/prometheus-cadvisor.json.j2 b/ansible/roles/prometheus/templates/prometheus-cadvisor.json.j2 new file mode 100644 index 0000000000..58070b943a --- /dev/null +++ b/ansible/roles/prometheus/templates/prometheus-cadvisor.json.j2 @@ -0,0 +1,11 @@ +{ + "command": "/opt/cadvisor --port={{ prometheus_cadvisor_port }} --log_dir=/var/log/kolla/prometheus", + "config_files": [], + "permissions": [ + { + "path": "/var/log/kolla/prometheus", + "owner": "prometheus:prometheus", + "recurse": true + } + ] +} diff --git a/ansible/roles/prometheus/templates/prometheus.yml.j2 b/ansible/roles/prometheus/templates/prometheus.yml.j2 index 7e3dbe70b8..77300676b5 100644 --- a/ansible/roles/prometheus/templates/prometheus.yml.j2 +++ b/ansible/roles/prometheus/templates/prometheus.yml.j2 @@ -48,3 +48,12 @@ scrape_configs: - '{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ hostvars[host]['prometheus_memcached_exporter_port'] }}' {% endfor %} {% endif %} + +{% if enable_prometheus_cadvisor | bool %} + - job_name: cadvisor + static_configs: + - targets: +{% for host in groups["prometheus-cadvisor"] %} + - '{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ hostvars[host]['prometheus_cadvisor_port'] }}' +{% endfor %} +{% endif %} diff --git a/ansible/site.yml b/ansible/site.yml index e94536ea20..25a15d6506 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -164,6 +164,7 @@ - prometheus-node-exporter - prometheus-mysqld-exporter - prometheus-haproxy-exporter + - prometheus-cadvisor serial: '{{ kolla_serial|default("0") }}' roles: - { role: prometheus, diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml index 61bada974b..75bc08372f 100644 --- a/etc/kolla/globals.yml +++ b/etc/kolla/globals.yml @@ -452,3 +452,4 @@ tempest_floating_network_name: #enable_prometheus_haproxy_exporter: "{{ enable_haproxy | bool }}" #enable_prometheus_mysqld_exporter: "{{ enable_mariadb | bool }}" #enable_prometheus_node_exporter: "yes" +#enable_prometheus_cadvisor: "yes" diff --git a/tests/templates/inventory.j2 b/tests/templates/inventory.j2 index 806705f5a1..4e27c0947a 100644 --- a/tests/templates/inventory.j2 +++ b/tests/templates/inventory.j2 @@ -640,3 +640,10 @@ mariadb [prometheus-haproxy-exporter:children] haproxy + +[prometheus-cadvisor:children] +monitoring +control +compute +network +storage