From 6c64b7c732efed50d48bf05aa6b04da9f07d7713 Mon Sep 17 00:00:00 2001 From: Jorge Niedbalski Date: Wed, 16 Jan 2019 18:37:16 -0300 Subject: [PATCH] [prometheus] Support the prometheus openstack exporter This patch implements the initial support for the openstack-exporter[0] in the kolla-ansible prometheus monitoring system. The configuration and prechecks are reused from the other exporters and a new template is provided for generating a os-client-config file required by the exporter. The default scrape interval is 60 seconds, but it can be extended via a configuration option. [0] https://github.com/Linaro/openstack-exporter Change-Id: I4a34c4bb56e74b5cd544972cbd6540d9acb6e4a1 --- ansible/group_vars/all.yml | 7 ++++++ ansible/inventory/all-in-one | 3 +++ ansible/inventory/multinode | 3 +++ ansible/roles/prometheus/defaults/main.yml | 16 +++++++++++++ ansible/roles/prometheus/handlers/main.yml | 21 +++++++++++++++++ ansible/roles/prometheus/tasks/config.yml | 17 ++++++++++++++ ansible/roles/prometheus/tasks/precheck.yml | 15 ++++++++++++ .../roles/prometheus/templates/clouds.yml.j2 | 12 ++++++++++ .../prometheus-openstack-exporter.json.j2 | 23 +++++++++++++++++++ .../prometheus/templates/prometheus.yml.j2 | 11 +++++++++ ansible/site.yml | 2 ++ etc/kolla/globals.yml | 1 + ...s-openstack-exporter-8fd7b0e6c8e71649.yaml | 5 ++++ tests/templates/inventory.j2 | 3 +++ 14 files changed, 139 insertions(+) create mode 100644 ansible/roles/prometheus/templates/clouds.yml.j2 create mode 100644 ansible/roles/prometheus/templates/prometheus-openstack-exporter.json.j2 create mode 100644 releasenotes/notes/add-prometheus-openstack-exporter-8fd7b0e6c8e71649.yaml diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index c808fd0eda..4fcc9e2839 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -304,6 +304,10 @@ prometheus_cadvisor_port: "18080" # Prometheus alertmanager ports prometheus_alertmanager_port: "9093" prometheus_alertmanager_cluster_port: "9094" + +# Prometheus openstack-exporter ports +prometheus_openstack_exporter_port: "9198" + qdrouterd_port: "31459" rabbitmq_port: "5672" @@ -924,7 +928,10 @@ enable_prometheus_memcached_exporter: "{{ enable_memcached | bool }}" enable_prometheus_cadvisor: "{{ enable_prometheus | bool }}" enable_prometheus_alertmanager: "{{ enable_prometheus | bool }}" enable_prometheus_ceph_mgr_exporter: "{{ enable_ceph | bool and enable_prometheus | bool }}" +enable_prometheus_openstack_exporter: "{{ enable_prometheus | bool }}" + prometheus_alertmanager_user: "admin" +prometheus_openstack_exporter_interval: "60s" ############ # Vitrage diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one index d795905e46..19e784cc93 100644 --- a/ansible/inventory/all-in-one +++ b/ansible/inventory/all-in-one @@ -732,3 +732,6 @@ storage [prometheus-alertmanager:children] monitoring + +[prometheus-openstack-exporter:children] +monitoring diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode index 98ae0d96cf..e8dec09320 100644 --- a/ansible/inventory/multinode +++ b/ansible/inventory/multinode @@ -751,3 +751,6 @@ storage [prometheus-alertmanager:children] monitoring + +[prometheus-openstack-exporter:children] +monitoring diff --git a/ansible/roles/prometheus/defaults/main.yml b/ansible/roles/prometheus/defaults/main.yml index 4a6dd96379..34c745b672 100644 --- a/ansible/roles/prometheus/defaults/main.yml +++ b/ansible/roles/prometheus/defaults/main.yml @@ -104,6 +104,17 @@ prometheus_services: port: "{{ prometheus_alertmanager_port }}" auth_user: "{{ prometheus_alertmanager_user }}" auth_pass: "{{ prometheus_alertmanager_password }}" + prometheus-openstack-exporter: + container_name: "prometheus_openstack_exporter" + group: "prometheus-openstack-exporter" + enabled: "{{ enable_prometheus_openstack_exporter | bool }}" + image: "{{ prometheus_openstack_exporter_image_full }}" + volumes: + - "{{ node_config_directory }}/prometheus-openstack-exporter/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + - "prometheus:/var/lib/prometheus" + dimensions: "{{ prometheus_openstack_exporter_dimensions }}" #################### # Database @@ -144,6 +155,10 @@ prometheus_alertmanager_image: "{{ docker_registry ~ '/' if docker_registry else prometheus_alertmanager_tag: "{{ openstack_release }}" prometheus_alertmanager_image_full: "{{ prometheus_alertmanager_image }}:{{ prometheus_alertmanager_tag }}" +# Prometheus openstack_exporter +prometheus_openstack_exporter_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-prometheus-openstack-exporter" +prometheus_openstack_exporter_tag: "{{ openstack_release }}" +prometheus_openstack_exporter_image_full: "{{ prometheus_openstack_exporter_image }}:{{ prometheus_openstack_exporter_tag }}" prometheus_server_dimensions: "{{ default_container_dimensions }}" prometheus_haproxy_exporter_dimensions: "{{ default_container_dimensions }}" prometheus_mysqld_exporter_dimensions: "{{ default_container_dimensions }}" @@ -151,3 +166,4 @@ prometheus_node_exporter_dimensions: "{{ default_container_dimensions }}" prometheus_memcached_exporter_dimensions: "{{ default_container_dimensions }}" prometheus_cadvisor_dimensions: "{{ default_container_dimensions }}" prometheus_alertmanager_dimensions: "{{ default_container_dimensions }}" +prometheus_openstack_exporter_dimensions: "{{ default_container_dimensions }}" diff --git a/ansible/roles/prometheus/handlers/main.yml b/ansible/roles/prometheus/handlers/main.yml index 368ffc9598..a6b7090e74 100644 --- a/ansible/roles/prometheus/handlers/main.yml +++ b/ansible/roles/prometheus/handlers/main.yml @@ -147,3 +147,24 @@ - config_json.changed | bool or prometheus_alertmanager_confs.changed | bool or prometheus_container.changed | bool + +- name: Restart prometheus-openstack-exporter container + vars: + service_name: "prometheus-openstack-exporter" + 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 }}" + dimensions: "{{ service.dimensions }}" + when: + - kolla_action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or prometheus_openstack_exporter_confs.changed | bool + or prometheus_container.changed | bool diff --git a/ansible/roles/prometheus/tasks/config.yml b/ansible/roles/prometheus/tasks/config.yml index 42d862bb76..1446052061 100644 --- a/ansible/roles/prometheus/tasks/config.yml +++ b/ansible/roles/prometheus/tasks/config.yml @@ -106,6 +106,23 @@ notify: - Restart prometheus-mysqld-exporter container +- name: Copying cloud config file for openstack exporter + vars: + service: "{{ prometheus_services['prometheus-openstack-exporter'] }}" + template: + src: "{{ item }}" + dest: "{{ node_config_directory }}/prometheus-openstack-exporter/clouds.yml" + register: prometheus_openstack_exporter_confs + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool + with_first_found: + - "{{ node_custom_config }}/prometheus-openstack-exporter/{{ inventory_hostname }}/clouds.yml" + - "{{ node_custom_config }}/prometheus-openstack-exporter/clouds.yml" + - "{{ role_path }}/templates/clouds.yml.j2" + notify: + - Restart prometheus-openstack-exporter container + - name: Check prometheus containers become: true kolla_docker: diff --git a/ansible/roles/prometheus/tasks/precheck.yml b/ansible/roles/prometheus/tasks/precheck.yml index bb5e03642b..ef402c8c24 100644 --- a/ansible/roles/prometheus/tasks/precheck.yml +++ b/ansible/roles/prometheus/tasks/precheck.yml @@ -9,6 +9,7 @@ - prometheus_mysqld_exporter - prometheus_cadvisor - prometheus_alertmanager + - prometheus_openstack_exporter register: container_facts - name: Checking free port for Prometheus server @@ -96,3 +97,17 @@ with_items: - "{{ prometheus_alertmanager_port }}" - "{{ prometheus_alertmanager_cluster_port }}" + +- name: Checking free ports for Prometheus openstack-exporter + wait_for: + host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" + port: "{{ item }}" + connect_timeout: 1 + timeout: 1 + state: stopped + when: + - container_facts['prometheus_openstack_exporter'] is not defined + - inventory_hostname in groups['prometheus-openstack-exporter'] + - enable_prometheus_openstack_exporter | bool + with_items: + - "{{ prometheus_openstack_exporter_port }}" diff --git a/ansible/roles/prometheus/templates/clouds.yml.j2 b/ansible/roles/prometheus/templates/clouds.yml.j2 new file mode 100644 index 0000000000..b7ba2849c9 --- /dev/null +++ b/ansible/roles/prometheus/templates/clouds.yml.j2 @@ -0,0 +1,12 @@ +clouds: + default: + region_name: {{ openstack_region_name }} + identity_api_version: 3 + identity_interface: internal + auth: + username: {{ keystone_admin_user }} + password: {{ keystone_admin_password }} + project_name: {{ keystone_admin_project }} + project_domain_name: 'Default' + user_domain_name: 'Default' + auth_url: {{ admin_protocol }}://{{ kolla_internal_fqdn }}:{{ keystone_admin_port }}/v3 diff --git a/ansible/roles/prometheus/templates/prometheus-openstack-exporter.json.j2 b/ansible/roles/prometheus/templates/prometheus-openstack-exporter.json.j2 new file mode 100644 index 0000000000..5b620f779d --- /dev/null +++ b/ansible/roles/prometheus/templates/prometheus-openstack-exporter.json.j2 @@ -0,0 +1,23 @@ +{ + "command": "/opt/openstack-exporter/openstack-exporter --os-client-config=/etc/openstack/clouds.yml --web.listen-address={{ api_interface_address }}:{{ prometheus_openstack_exporter_port }} default", + "config_files": [ + { + "source": "{{ container_config_directory }}/clouds.yml", + "dest": "/etc/openstack/clouds.yml", + "owner": "prometheus", + "perm": "0600" + } + ], + "permissions": [ + { + "path": "/data", + "owner": "prometheus:kolla", + "recurse": true + }, + { + "path": "/var/log/kolla/prometheus", + "owner": "prometheus:kolla", + "recurse": true + } + ] +} diff --git a/ansible/roles/prometheus/templates/prometheus.yml.j2 b/ansible/roles/prometheus/templates/prometheus.yml.j2 index 5bcb48dbf6..1d8e3168b7 100644 --- a/ansible/roles/prometheus/templates/prometheus.yml.j2 +++ b/ansible/roles/prometheus/templates/prometheus.yml.j2 @@ -75,6 +75,17 @@ scrape_configs: {% endfor %} {% endif %} +{% if enable_prometheus_openstack_exporter | bool %} + - job_name: openstack_exporter + scrape_interval: {{ prometheus_openstack_exporter_interval }} + honor_labels: true + static_configs: + - targets: +{% for host in groups["prometheus-openstack-exporter"] %} + - '{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ hostvars[host]['prometheus_openstack_exporter_port'] }}' +{% endfor %} +{% endif %} + {% if enable_prometheus_alertmanager | bool %} alerting: alertmanagers: diff --git a/ansible/site.yml b/ansible/site.yml index 3cc9b0b886..ffcece9517 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -464,6 +464,8 @@ - prometheus-mysqld-exporter - prometheus-haproxy-exporter - prometheus-cadvisor + - prometheus-alertmanager + - prometheus-openstack-exporter - '&enable_prometheus_True' serial: '{{ kolla_serial|default("0") }}' roles: diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml index 072847ffa7..83e8cfc0ab 100644 --- a/etc/kolla/globals.yml +++ b/etc/kolla/globals.yml @@ -543,3 +543,4 @@ tempest_floating_network_name: #enable_prometheus_memcached: "{{ enable_prometheus | bool }}" #enable_prometheus_alertmanager: "{{ enable_prometheus | bool }}" #enable_prometheus_ceph_mgr_exporter: "{{ enable_prometheus | bool and enable_ceph | bool }}" +#enable_prometheus_openstack_exporter: "{{ enable_prometheus | bool }}" diff --git a/releasenotes/notes/add-prometheus-openstack-exporter-8fd7b0e6c8e71649.yaml b/releasenotes/notes/add-prometheus-openstack-exporter-8fd7b0e6c8e71649.yaml new file mode 100644 index 0000000000..2824437822 --- /dev/null +++ b/releasenotes/notes/add-prometheus-openstack-exporter-8fd7b0e6c8e71649.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Deploys and configures the prometheus-openstack-exporter (https://github.com/Linaro/openstack-exporter/) + as part of the prometheus monitoring exporters stack. diff --git a/tests/templates/inventory.j2 b/tests/templates/inventory.j2 index 2056bfa7e3..3a891923b9 100644 --- a/tests/templates/inventory.j2 +++ b/tests/templates/inventory.j2 @@ -661,3 +661,6 @@ control compute network storage + +[prometheus-openstack-exporter:children] +monitoring