Skip to content

Commit

Permalink
Merge pull request #598 from Capgemini/580-consul-health-checks
Browse files Browse the repository at this point in the history
Initial commit for #580 - add consul health checks based on consul 0.6
  • Loading branch information
tayzlor committed Jan 8, 2016
2 parents 4af446a + ee90521 commit c96701d
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 91 deletions.
21 changes: 6 additions & 15 deletions roles/cadvisor/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 9 additions & 6 deletions roles/cadvisor/templates/cadvisor-consul.j2
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
60 changes: 35 additions & 25 deletions roles/mesos/tasks/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 25 additions & 25 deletions roles/mesos/tasks/slave.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions roles/mesos/templates/mesos-exporter-consul.j2
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Empty file.
18 changes: 9 additions & 9 deletions roles/prometheus/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions roles/prometheus/templates/node-exporter-consul.j2
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
10 changes: 10 additions & 0 deletions roles/zookeeper/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion roles/zookeeper/templates/zookeeper-consul.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down

0 comments on commit c96701d

Please sign in to comment.