From ee905219650e6785054782b75a47d5b15053cd38 Mon Sep 17 00:00:00 2001 From: Graham Taylor Date: Tue, 5 Jan 2016 17:24:10 +0000 Subject: [PATCH] Initial commit for #580 - add consul health checks based on consul 0.6 for services --- roles/cadvisor/tasks/main.yml | 21 ++----- roles/cadvisor/templates/cadvisor-consul.j2 | 15 +++-- roles/mesos/tasks/master.yml | 60 +++++++++++-------- roles/mesos/tasks/slave.yml | 50 ++++++++-------- .../mesos/templates/mesos-exporter-consul.j2 | 12 ++-- roles/mesos/templates/mesos-slave-consul.j2 | 0 roles/prometheus/tasks/main.yml | 18 +++--- .../templates/node-exporter-consul.j2 | 13 ++-- roles/zookeeper/tasks/main.yml | 10 ++++ roles/zookeeper/templates/zookeeper-consul.j2 | 4 +- 10 files changed, 112 insertions(+), 91 deletions(-) create mode 100644 roles/mesos/templates/mesos-slave-consul.j2 diff --git a/roles/cadvisor/tasks/main.yml b/roles/cadvisor/tasks/main.yml index 9eaca3c8..2415a95d 100644 --- a/roles/cadvisor/tasks/main.yml +++ b/roles/cadvisor/tasks/main.yml @@ -20,21 +20,12 @@ tags: - cadvisor -- name: get cadvisor container ip +- name: Set cadvisor consul service definition sudo: yes - command: > - docker inspect -f \{\{' '.NetworkSettings.IPAddress' '\}\} cadvisor - register: cadvisor_container_ip + template: + src: cadvisor-consul.j2 + dest: "{{ cadvisor_consul_dir }}/cadvisor.json" + notify: + - restart consul tags: - cadvisor - -#- name: Set cadvisor consul service definition -# sudo: yes -# template: -# src: cadvisor-consul.j2 -# dest: "{{ cadvisor_consul_dir }}/cadvisor.json" -# notify: -# - restart consul -# when: cadvisor_enabled -# tags: -# - cadvisor diff --git a/roles/cadvisor/templates/cadvisor-consul.j2 b/roles/cadvisor/templates/cadvisor-consul.j2 index 35c1c447..c5aa2108 100644 --- a/roles/cadvisor/templates/cadvisor-consul.j2 +++ b/roles/cadvisor/templates/cadvisor-consul.j2 @@ -1,9 +1,12 @@ { - "check": { - "id": "cadvisor", - "name": "cadvisor status", - "service_id": "{{ cadvisor_consul_service_id }}", - "script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ cadvisor_container_ip.stdout }}:8080", - "interval": "10s" + "service": { + "name": "cadvisor", + "tags": [ "cadvisor" ], + "check": { + "docker_container_id": "cadvisor", + "shell": "/bin/sh", + "script": "wget -q --spider 127.0.0.1:8080/containers/ -O /dev/null", + "interval": "10s" + } } } diff --git a/roles/mesos/tasks/master.yml b/roles/mesos/tasks/master.yml index 5389e71e..3aa47c5f 100644 --- a/roles/mesos/tasks/master.yml +++ b/roles/mesos/tasks/master.yml @@ -29,29 +29,39 @@ tags: - mesos-master -#- name: run prometheus mesos master exporter container -# when: mesos_install_mode == "master" and prometheus_enabled|bool -# docker: -# name: mesos-exporter -# image: "{{ prometheus_mesos_exporter_image }}" -# command: "-exporter.scrape-mode=master -exporter.url=http://{{ mesos_hostname }}:{{ mesos_master_port }}" -# state: started -# restart_policy: always -# ports: -# - "{{ prometheus_mesos_exporter_port }}:{{ prometheus_mesos_exporter_port }}" -# environment: proxy_env -# tags: -# - prometheus -# - mesos_master +- name: Set mesos-master consul service definition + sudo: yes + template: + src: mesos-master-consul.j2 + dest: "{{ consul_dir }}/mesos-master.json" + notify: + - restart consul + tags: + - mesos-master + +- name: run prometheus mesos master exporter container + when: prometheus_enabled|bool + docker: + name: mesos-exporter + image: "{{ prometheus_mesos_exporter_image }}" + command: "-exporter.scrape-mode=master -exporter.url=http://{{ mesos_hostname }}:{{ mesos_master_port }}" + state: started + restart_policy: always + ports: + - "{{ prometheus_mesos_exporter_port }}:{{ prometheus_mesos_exporter_port }}" + environment: proxy_env + tags: + - prometheus + - mesos_master -#- name: Set mesos-exporter consul service definition -# when: mesos_install_mode == "master" and prometheus_enabled|bool -# sudo: yes -# template: -# src: mesos-exporter-consul.j2 -# dest: "{{ consul_dir }}/mesos-exporter.json" -# notify: -# - restart consul -# tags: -# - prometheus -# - mesos_master +- name: Set mesos-exporter consul service definition + when: prometheus_enabled|bool + sudo: yes + template: + src: mesos-exporter-consul.j2 + dest: "{{ consul_dir }}/mesos-exporter.json" + notify: + - restart consul + tags: + - prometheus + - mesos_master diff --git a/roles/mesos/tasks/slave.yml b/roles/mesos/tasks/slave.yml index 88469c12..017cafb7 100644 --- a/roles/mesos/tasks/slave.yml +++ b/roles/mesos/tasks/slave.yml @@ -29,29 +29,29 @@ tags: - mesos-slave -#- name: run prometheus mesos slave exporter container -# when: mesos_install_mode == "slave" and prometheus_enabled|bool -# docker: -# name: mesos-exporter -# image: "{{ prometheus_mesos_exporter_image }}" -# command: "-exporter.scrape-mode=slave -exporter.url=http://{{ mesos_hostname }}:{{ mesos_slave_port }}" -# state: started -# restart_policy: always -# ports: -# - "{{ prometheus_mesos_exporter_port }}:{{ prometheus_mesos_exporter_port }}" -# environment: proxy_env -# tags: -# - prometheus -# - mesos_slave +- name: run prometheus mesos slave exporter container + when: prometheus_enabled|bool + docker: + name: mesos-exporter + image: "{{ prometheus_mesos_exporter_image }}" + command: "-exporter.scrape-mode=slave -exporter.url=http://{{ mesos_hostname }}:{{ mesos_slave_port }}" + state: started + restart_policy: always + ports: + - "{{ prometheus_mesos_exporter_port }}:{{ prometheus_mesos_exporter_port }}" + environment: proxy_env + tags: + - prometheus + - mesos_slave -#- name: Set mesos-exporter consul service definition -# when: mesos_install_mode == "slave" and prometheus_enabled|bool -# sudo: yes -# template: -# src: mesos-exporter-consul.j2 -# dest: "{{ consul_dir }}/mesos-exporter.json" -# notify: -# - restart consul -# tags: -# - prometheus -# - mesos_slave +- name: Set mesos-exporter consul service definition + when: prometheus_enabled|bool + sudo: yes + template: + src: mesos-exporter-consul.j2 + dest: "{{ consul_dir }}/mesos-exporter.json" + notify: + - restart consul + tags: + - prometheus + - mesos_slave diff --git a/roles/mesos/templates/mesos-exporter-consul.j2 b/roles/mesos/templates/mesos-exporter-consul.j2 index 3aa3260b..255ef5d8 100644 --- a/roles/mesos/templates/mesos-exporter-consul.j2 +++ b/roles/mesos/templates/mesos-exporter-consul.j2 @@ -1,9 +1,11 @@ { - "check": { + "service": { "id": "mesos-exporter", - "name": "mesos exporter status", - "service_id": "{{ prometheus_mesos_exporter_consul_service_id }}", - "script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ mesos_hostname }}:{{ prometheus_mesos_exporter_port }}", - "interval": "10s" + "name": "prometheus-mesos-exporter", + "tags": [ "mesos", "prometheus" ], + "check": { + "script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ mesos_hostname }}:{{ prometheus_mesos_exporter_port }}", + "interval": "10s" + } } } diff --git a/roles/mesos/templates/mesos-slave-consul.j2 b/roles/mesos/templates/mesos-slave-consul.j2 new file mode 100644 index 00000000..e69de29b diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml index 577dd25a..7ebb6dda 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -30,12 +30,12 @@ tags: - prometheus -#- name: Set node-exporter consul service definition -# sudo: yes -# template: -# src: node-exporter-consul.j2 -# dest: "{{ prometheus_consul_dir }}/node-exporter.json" -# notify: -# - restart consul -# tags: -# - prometheus +- name: set node-exporter consul service definition + sudo: yes + template: + src: node-exporter-consul.j2 + dest: "{{ prometheus_consul_dir }}/node-exporter.json" + notify: + - restart consul + tags: + - prometheus diff --git a/roles/prometheus/templates/node-exporter-consul.j2 b/roles/prometheus/templates/node-exporter-consul.j2 index 624dd754..94ce3ea5 100644 --- a/roles/prometheus/templates/node-exporter-consul.j2 +++ b/roles/prometheus/templates/node-exporter-consul.j2 @@ -1,9 +1,12 @@ { - "check": { + "service": { "id": "node-exporter", - "name": "node exporter status", - "service_id": "{{ prometheus_node_exporter_consul_service_id }}", - "script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ prometheus_node_exporter_hostname }}:{{ prometheus_node_exporter_port }}", - "interval": "10s" + "name": "prometheus-node-exporter", + "port": {{ prometheus_node_exporter_port }}, + "tags": [ "prometheus" ], + "check": { + "script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ prometheus_node_exporter_hostname }}:{{ prometheus_node_exporter_port }}", + "interval": "10s" + } } } diff --git a/roles/zookeeper/tasks/main.yml b/roles/zookeeper/tasks/main.yml index 846735c7..192c2953 100644 --- a/roles/zookeeper/tasks/main.yml +++ b/roles/zookeeper/tasks/main.yml @@ -57,3 +57,13 @@ state: started tags: - zookeeper + +- name: set zookeeper consul service definition + sudo: yes + template: + src: zookeeper-consul.j2 + dest: "{{ consul_dir }}/zookeeper.json" + notify: + - restart consul + tags: + - zookeeper diff --git a/roles/zookeeper/templates/zookeeper-consul.j2 b/roles/zookeeper/templates/zookeeper-consul.j2 index 1d3072fb..d05d3fc6 100644 --- a/roles/zookeeper/templates/zookeeper-consul.j2 +++ b/roles/zookeeper/templates/zookeeper-consul.j2 @@ -4,7 +4,9 @@ "port": {{ zookeeper_client_port }}, "tags": [ "zookeeper" ], "check": { - "script": "echo ruok | nc {{ ansible_ssh_host }} {{ zookeeper_client_port }} | grep imok", + "docker_container_id": "zookeeper", + "shell": "/bin/bash", + "script": "echo ruok | nc 127.0.0.1 {{ zookeeper_client_port }} | grep imok", "interval": "10s" } }