Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

55 cadvisor #354

Merged
merged 3 commits into from
Jul 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootstrap/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ open_urls() {
/usr/bin/open "http://$(terraform output master.1.ip):8080"
/usr/bin/open "http://$(terraform output master.1.ip):8500"
/usr/bin/open "http://$(terraform output master.1.ip):4040"
/usr/bin/open "http://$(terraform output master.1.ip):8081"
fi
popd
}
Expand Down
10 changes: 10 additions & 0 deletions roles/cadvisor/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# defaults file for cadvisor
cadvisor_enabled: true
cadvisor_version: 'latest'
cadvisor_host_port: 8081
cadvisor_restart_policy: 'always'
cadvisor_net: 'bridge'
cadvisor_hostname: "{{ ansible_ssh_host }}"
cadvisor_image: "google/cadvisor:{{ cadvisor_version }}"
cadvisor_consul_dir: /etc/consul.d
Empty file.
130 changes: 130 additions & 0 deletions roles/cadvisor/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
galaxy_info:
author: Alberto Lamela
description:
company: Capgemini
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (MIT)
min_ansible_version: 1.2
#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
# platform on this list, let us know and we'll get it added!
#
platforms:
#- name: EL
# versions:
# - all
# - 5
# - 6
# - 7
#- name: GenericUNIX
# versions:
# - all
# - any
#- name: Fedora
# versions:
# - all
# - 16
# - 17
# - 18
# - 19
# - 20
#- name: SmartOS
# versions:
# - all
# - any
#- name: opensuse
# versions:
# - all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
- name: Ubuntu
versions:
# - all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
- trusty
#- name: SLES
# versions:
# - all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
#- name: GenericLinux
# versions:
# - all
# - any
#- name: Debian
# versions:
# - all
# - etch
# - lenny
# - squeeze
# - wheezy
#
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
#
categories:
- cloud
#- cloud:ec2
#- cloud:gce
#- cloud:rax
#- clustering
#- database
#- database:nosql
#- database:sql
#- development
#- monitoring
#- networking
#- packaging
- system
#- web
dependencies:
# - role: consul
# - role: registrator
# - role: zookeeper
# List your role dependencies here, one per line. Only
# dependencies available via galaxy should be listed here.
# Be sure to remove the '[]' above if you add dependencies
# to this list.
64 changes: 64 additions & 0 deletions roles/cadvisor/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Install (docker-py) python package as is a docker module dependency.
- pip: name=docker-py version=1.1.0

# tasks for running cadvisor
- name: run cadvisor container
when: cadvisor_enabled
docker:
name: cadvisor
image: "{{ cadvisor_image }}"
state: started
restart_policy: "{{ cadvisor_restart_policy }}"
net: "{{ cadvisor_net }}"
ports:
- "{{ cadvisor_host_port }}:8080"
hostname: "{{ cadvisor_hostname }}"
volumes:
- "/var/lib/docker/:/var/lib/docker:ro"
- "/:/rootfs:ro"
- "/var/run:/var/run:rw"
- "/sys:/sys:ro"
tags:
- cadvisor

- name: upload cadvisor template service
when: cadvisor_enabled
template:
src: cadvisor.conf.j2
dest: /etc/init/cadvisor.conf
mode: 0755
sudo: yes
tags:
- cadvisor

# Attach to the running container, or start it if needed
# and forward all signals so that the process manager can detect
# when a container stops and correctly restart it.
- name: ensure cadvisor is running (and enable it at boot)
when: cadvisor_enabled
sudo: yes
service:
name: cadvisor
state: started
enabled: yes
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

- name: ensure cadvisor is running (and enable it at boot)
when: not cadvisor_enabled
sudo: yes
service:
name: cadvisor
state: stopped
enabled: yes
tags:
- cadvisor
11 changes: 11 additions & 0 deletions roles/cadvisor/templates/cadvisor-consul.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"service": {
"name": "cadvisor",
"tags": [ "cadvisor" ],
"port": {{ cadvisor_host_port }},
"check": {
"script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ cadvisor_hostname }}:{{ cadvisor_host_port}}",
"interval": "10s"
}
}
}
12 changes: 12 additions & 0 deletions roles/cadvisor/templates/cadvisor.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description "cadvisor container"

start on started docker
stop on stopping docker

script
/usr/bin/docker start -a cadvisor
end script

respawn
respawn limit 10 10
kill timeout 10
2 changes: 2 additions & 0 deletions roles/cadvisor/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for cadvisor
1 change: 1 addition & 0 deletions roles/marathon/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
# defaults file for marathon
marathon_consul_dir: /etc/consul.d
marathon_enabled: true
marathon_version: '0.8.2'
marathon_restart_policy: 'always'
Expand Down
9 changes: 9 additions & 0 deletions roles/marathon/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
tags:
- marathon

- name: Set marathon consul service definition
sudo: yes
template:
src: marathon-consul.j2
dest: "{{ marathon_consul_dir }}/marathon.json"
notify:
- restart consul
when: marathon_enabled

# tasks for stoping docker marathon
- name: stop marathon container
when: not marathon_enabled
Expand Down
1 change: 1 addition & 0 deletions site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- docker
- weave
- registrator
- cadvisor

- hosts: mesos_masters
roles:
Expand Down
3 changes: 3 additions & 0 deletions tests/properties.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mesos_masters:
- weave
- docker
- registrator
- cadvisor
mesos_slaves:
:roles:
- dnsmasq
Expand All @@ -16,6 +17,8 @@ mesos_slaves:
- weave
- docker
- registrator
- cadvisor
load_balancers:
:roles:
- haproxy
- cadvisor
17 changes: 17 additions & 0 deletions tests/spec/cadvisor/cadvisor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe docker_container('cadvisor') do
it { should be_running }
it { should have_volume('/var/lib/docker','/var/lib/docker') }
it { should have_volume('/rootfs','/') }
it { should have_volume('/var/run','/var/run') }
it { should have_volume('/sys','/sys') }
end

describe port(8081) do
it { should be_listening }
end

describe service('cadvisor') do
it { should be_running }
end