diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 1b9dff1b86..74f81f21f1 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -263,6 +263,7 @@ enable_rally: "no" enable_sahara: "no" enable_senlin: "no" enable_swift: "no" +enable_telegraf: "no" enable_tempest: "no" enable_watcher: "no" diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one index a1dcf2f8bf..dacc37e2cf 100644 --- a/ansible/inventory/all-in-one +++ b/ansible/inventory/all-in-one @@ -23,6 +23,9 @@ compute [kibana:children] control +[telegraf:children] +monitoring + [elasticsearch:children] control diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode index be0dc85dca..1462c4f278 100644 --- a/ansible/inventory/multinode +++ b/ansible/inventory/multinode @@ -44,6 +44,9 @@ monitoring [kibana:children] control +[telegraf:children] +monitoring + [elasticsearch:children] control diff --git a/ansible/roles/telegraf/defaults/main.yml b/ansible/roles/telegraf/defaults/main.yml new file mode 100644 index 0000000000..c11bf0a379 --- /dev/null +++ b/ansible/roles/telegraf/defaults/main.yml @@ -0,0 +1,18 @@ +--- +project_name: "telegraf" + +#################### +# Docker +#################### +telegraf_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-telegraf" +telegraf_tag: "{{ openstack_release }}" +telegraf_image_full: "{{ telegraf_image }}:{{ telegraf_tag }}" + + +#################### +# Protocols +#################### +elasticsearch_proto: "http" +haproxy_proto: "http" +influxdb_proto: "http" +rabbitmq_proto: "http" diff --git a/ansible/roles/telegraf/meta/main.yml b/ansible/roles/telegraf/meta/main.yml new file mode 100644 index 0000000000..6b4fff8fef --- /dev/null +++ b/ansible/roles/telegraf/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: common } diff --git a/ansible/roles/telegraf/tasks/config.yml b/ansible/roles/telegraf/tasks/config.yml new file mode 100644 index 0000000000..19f8697601 --- /dev/null +++ b/ansible/roles/telegraf/tasks/config.yml @@ -0,0 +1,26 @@ +--- +- name: Ensuring config directories exist + file: + path: "{{ node_config_directory }}/{{ item }}" + state: "directory" + recurse: yes + with_items: + - "telegraf" + - "telegraf/config" + +- name: Copying over default config.json files + template: + src: "telegraf.json.j2" + dest: "{{ node_config_directory }}/telegraf/config.json" + +- name: Copying over telegraf config file + template: + src: "telegraf.conf.j2" + dest: "{{ node_config_directory }}/telegraf/telegraf.conf" + +- name: Copying over telegraf plugin files + copy: + src: "{{ item }}" + dest: "{{ node_config_directory }}/telegraf/config" + with_fileglob: + - "{{ role_path }}/templates/config/*.conf" diff --git a/ansible/roles/telegraf/tasks/deploy.yml b/ansible/roles/telegraf/tasks/deploy.yml new file mode 100644 index 0000000000..1f16915ad9 --- /dev/null +++ b/ansible/roles/telegraf/tasks/deploy.yml @@ -0,0 +1,4 @@ +--- +- include: config.yml + +- include: start.yml diff --git a/ansible/roles/telegraf/tasks/do_reconfigure.yml b/ansible/roles/telegraf/tasks/do_reconfigure.yml new file mode 100644 index 0000000000..68a27d8a57 --- /dev/null +++ b/ansible/roles/telegraf/tasks/do_reconfigure.yml @@ -0,0 +1,42 @@ +--- +- name: Ensuring the containers up + kolla_docker: + name: "telegraf" + action: "get_container_state" + register: container_state + failed_when: container_state.Running == false + +- include: config.yml + +- name: Check the configs + command: docker exec telegraf /usr/local/bin/kolla_set_configs --check + changed_when: false + failed_when: false + register: check_results + +# NOTE(jeffrey4l): when config_strategy == 'COPY_ALWAYS' +# and container env['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE', +# just remove the container and start again +- name: Containers config strategy + kolla_docker: + name: "telegraf" + action: "get_container_env" + register: container_envs + +- name: Remove the containers + kolla_docker: + name: "telegraf" + action: "remove_container" + register: remove_containers + when: + - config_strategy == "COPY_ONCE" + +- include: start.yml + when: remove_containers.changed + +- name: Restart containers + kolla_docker: + name: "telegraf" + action: "restart_container" + when: + - config_strategy == 'COPY_ALWAYS' diff --git a/ansible/roles/telegraf/tasks/main.yml b/ansible/roles/telegraf/tasks/main.yml new file mode 100644 index 0000000000..b017e8b4ad --- /dev/null +++ b/ansible/roles/telegraf/tasks/main.yml @@ -0,0 +1,2 @@ +--- +- include: "{{ action }}.yml" diff --git a/ansible/roles/telegraf/tasks/pull.yml b/ansible/roles/telegraf/tasks/pull.yml new file mode 100644 index 0000000000..e1a5b45703 --- /dev/null +++ b/ansible/roles/telegraf/tasks/pull.yml @@ -0,0 +1,6 @@ +--- +- name: Pulling telegraf image + kolla_docker: + action: "pull_image" + common_options: "{{ docker_common_options }}" + image: "{{ telegraf_image_full }}" diff --git a/ansible/roles/telegraf/tasks/reconfigure.yml b/ansible/roles/telegraf/tasks/reconfigure.yml new file mode 100644 index 0000000000..2a1e32d9c2 --- /dev/null +++ b/ansible/roles/telegraf/tasks/reconfigure.yml @@ -0,0 +1,2 @@ +--- +- include: do_reconfigure.yml diff --git a/ansible/roles/telegraf/tasks/start.yml b/ansible/roles/telegraf/tasks/start.yml new file mode 100644 index 0000000000..443b072498 --- /dev/null +++ b/ansible/roles/telegraf/tasks/start.yml @@ -0,0 +1,19 @@ +--- +- name: Starting telegraf container + kolla_docker: + action: "start_container" + common_options: "{{ docker_common_options }}" + image: "{{ telegraf_image_full }}" + name: "telegraf" + environment: + HOST_PROC: "/rootfs/proc" + HOST_SYS: "/rootfs/sys" + volumes: + - "{{ node_config_directory }}/telegraf/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + - "/sys:/rootfs/sys:ro" + - "/proc:/rootfs/proc:ro" + - "/var/run/docker.sock:/var/run/docker.sock:ro" + - "haproxy_socket:/var/lib/kolla/haproxy/:rw" + pid_mode: "host" diff --git a/ansible/roles/telegraf/tasks/upgrade.yml b/ansible/roles/telegraf/tasks/upgrade.yml new file mode 100644 index 0000000000..1f16915ad9 --- /dev/null +++ b/ansible/roles/telegraf/tasks/upgrade.yml @@ -0,0 +1,4 @@ +--- +- include: config.yml + +- include: start.yml diff --git a/ansible/roles/telegraf/templates/telegraf.conf.j2 b/ansible/roles/telegraf/templates/telegraf.conf.j2 new file mode 100644 index 0000000000..0788f854d4 --- /dev/null +++ b/ansible/roles/telegraf/templates/telegraf.conf.j2 @@ -0,0 +1,55 @@ +[global_tags] +[agent] + interval = "10s" + round_interval = true + metric_batch_size = 1000 + metric_buffer_limit = 10000 + collection_jitter = "0s" + flush_interval = "10s" + flush_jitter = "0s" + debug = false + quiet = false + hostname = "" + omit_hostname = false +[[outputs.influxdb]] + urls = [{% for host in groups['influxdb'] %}"{{ influxdb_proto }}://{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address']}}:{{ influxdb_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}] + database = "telegraf" # required + retention_policy = "default" + write_consistency = "any" + timeout = "5s" +[[inputs.filestat]] +files = ["/var/log/kolla/**.log"] +[[inputs.cpu]] + percpu = true + totalcpu = true + fielddrop = ["time_*"] +[[inputs.disk]] + ignore_fs = ["tmpfs", "devtmpfs"] +[[inputs.diskio]] +[[inputs.kernel]] +[[inputs.mem]] +[[inputs.processes]] +[[inputs.swap]] +[[inputs.system]] +[[inputs.net]] + interfaces = [] +{% if enable_haproxy | bool %} +[[inputs.haproxy]] + servers = ["{{ haproxy_proto }}://{{ haproxy_user }}:{{ haproxy_password }}@{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ haproxy_stats_port }}"] +{% endif %} +{% if enable_memcached | bool %} +[[inputs.memcached]] + servers = ["{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ memcached_port }}"] +{% endif %} +{% if enable_elasticsearch | bool %} +[[inputs.elasticsearch]] + servers = ["{{ elasticsearch_proto }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ elasticsearch_port }}"] + local = true + cluster_health = true +{% endif %} +{% if inventory_hostname in groups['rabbitmq'] %} +[[inputs.rabbitmq]] + url = "{{ rabbitmq_proto }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ rabbitmq_management_port }}" + username = "{{ rabbitmq_user }}" + password = "{{ rabbitmq_password }}" +{% endif %} diff --git a/ansible/roles/telegraf/templates/telegraf.json.j2 b/ansible/roles/telegraf/templates/telegraf.json.j2 new file mode 100644 index 0000000000..324d4efb8e --- /dev/null +++ b/ansible/roles/telegraf/templates/telegraf.json.j2 @@ -0,0 +1,17 @@ +{ + "command": "telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d/", + "config_files": [ + { + "source": "{{ container_config_directory }}/telegraf.conf", + "dest": "/etc/telegraf/telegraf.conf", + "owner": "telegraf", + "perm": "0600" + }, + { + "source": "{{ container_config_directory }}/config/*", + "dest": "/etc/telegraf/telegraf.d/", + "owner": "telegraf", + "perm": "0600" + } + ] +} diff --git a/ansible/site.yml b/ansible/site.yml index 67f1e2a32e..e83027d851 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -28,6 +28,14 @@ tags: influxdb, when: enable_influxdb | bool } +- hosts: + - telegraf + serial: '{{ "30%" if action == "upgrade" else "0" }}' + roles: + - { role: telegraf, + tags: telegraf, + when: enable_telegraf | bool } + - hosts: haproxy serial: '{{ "30%" if action == "upgrade" else "0" }}' roles: diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml index 26ddbddf70..a24c053f86 100644 --- a/etc/kolla/globals.yml +++ b/etc/kolla/globals.yml @@ -137,6 +137,7 @@ kolla_internal_vip_address: "10.10.10.254" #enable_rally: "no" #enable_senlin: "no" #enable_swift: "no" +#enable_telegraf: "no" #enable_tempest: "no" #enable_watcher: "no"