-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from hellofresh/patch/CRS-1632-add-cadvisor
CRS-1632 Add cadvisor
- Loading branch information
Showing
12 changed files
with
293 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
--- | ||
|
||
dockerhost_group : "docker" | ||
docker_compose_version : "1.25.3" | ||
docker_compose_dir : "/opt/docker_compose" | ||
docker_compose_install : True | ||
docker_install_py_module : False | ||
dockerhost_group : "docker" | ||
docker_compose_version : "1.29.1" | ||
docker_compose_dir : "/opt/docker_compose" | ||
docker_compose_install : True | ||
docker_install_py_module : False | ||
|
||
docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg | ||
docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg | ||
|
||
dockerhost_daemon_config : {} | ||
|
||
dockerhost_install_cadvisor : True | ||
dockerhost_prometheus_exporters_common_user : prometheus | ||
dockerhost_prometheus_exporters_common_group : prometheus | ||
|
||
dockerhost_prometheus_exporters_common_root_dir : /opt/prometheus/exporters | ||
dockerhost_prometheus_exporters_common_dist_dir : "{{ dockerhost_prometheus_exporters_common_root_dir }}/dist" | ||
dockerhost_prometheus_exporters_common_conf_dir : "/etc/prometheus/exporters" | ||
|
||
dockerhost_cadvisor_version : v0.37.5 | ||
dockerhost_cadvisor_release_name : "cadvisor-{{ dockerhost_cadvisor_version }}.linux-amd64" | ||
dockerhost_cadvisor_config_flags : {} | ||
dockerhost_cadvisor_config_docker_endpoint : unix:///run/docker.sock | ||
dockerhost_cadvisor_config_listen_port : 8100 | ||
dockerhost_cadvisor_config_listen_interface : 0.0.0.0 | ||
|
||
# Since cAdvisor can potentially replace node exporter, add an option to disable node exporter | ||
dockerhost_disable_prometheus_node_exporter : False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
--- | ||
- name: restart docker | ||
service: | ||
service: | ||
name: docker | ||
state: restarted | ||
|
||
- name: restart docker systemd | ||
systemd: | ||
systemd: | ||
name: docker | ||
state: restarted | ||
daemon_reload: True | ||
|
||
- name: reenable cadvisor service | ||
command: systemctl reenable cadvisor.service | ||
|
||
- name: reinit cadvisor | ||
command: initctl reload-configuration | ||
|
||
- name: restart cadvisor | ||
service: | ||
name: cadvisor | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
|
||
- name: Create binary directory | ||
file: | ||
path: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ dockerhost_cadvisor_release_name }}" | ||
state: directory | ||
owner: "{{ dockerhost_prometheus_exporters_common_user }}" | ||
group: "{{ dockerhost_prometheus_exporters_common_group }}" | ||
|
||
- name: download cadvisor binary | ||
get_url: | ||
url: "{{ dockerhost_cadvisor_download_url }}" | ||
dest: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ dockerhost_cadvisor_release_name }}/cadvisor" | ||
mode: "0755" | ||
|
||
- name: create symlink to the current release | ||
file: | ||
src: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ dockerhost_cadvisor_release_name }}" | ||
path: "{{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current" | ||
state: link | ||
|
||
- name: create systemd service unit | ||
template: | ||
src: cadvisor/systemd-unit.j2 | ||
dest: /etc/systemd/system/cadvisor.service | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
when: ansible_service_mgr == 'systemd' | ||
notify: | ||
- reenable cadvisor service | ||
- restart cadvisor | ||
|
||
- name: get upstart version | ||
command: initctl version | ||
when: ansible_service_mgr == 'upstart' | ||
register: upstart_version | ||
|
||
- name: create init service unit | ||
template: | ||
src: cadvisor/upstart.j2 | ||
dest: /etc/init/cadvisor.conf | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
when: ansible_service_mgr == 'upstart' | ||
notify: | ||
- reinit cadvisor | ||
- restart cadvisor | ||
|
||
- name: create sysvinit service unit | ||
template: | ||
src: cadvisor/init.j2 | ||
dest: /etc/init.d/cadvisor | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: ansible_service_mgr == 'sysvinit' | ||
notify: | ||
- restart cadvisor | ||
|
||
- name: disable node exporter service | ||
when: dockerhost_disable_prometheus_node_exporter|bool | ||
service: | ||
name: prometheus-node-exporter | ||
state: stopped | ||
enabled: no | ||
|
||
- meta: flush_handlers | ||
|
||
- name: ensure cadvisor is running | ||
service: | ||
name: cadvisor | ||
enabled: yes | ||
state: started |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/bin/sh | ||
# | ||
# <daemonname> <summary> | ||
# | ||
# chkconfig: 345 99 01 | ||
# description: Manage service cadvisor | ||
|
||
|
||
### BEGIN INIT INFO | ||
# Provides: cadvisor | ||
# Required-Start: | ||
# Required-Stop: | ||
# Should-Start: | ||
# Should-Stop: | ||
# Default-Start: | ||
# Default-Stop: | ||
# Short-Description: | ||
# Description: Manage service cadvisor | ||
### END INIT INFO | ||
|
||
# Source function library. | ||
. /etc/rc.d/init.d/functions | ||
|
||
exec="/opt/prometheus/exporters/cadvisor_current/cadvisor" | ||
prog="cadvisor" | ||
# cadvisor is not able to manage configuration file | ||
#config="<path to major config file>" | ||
|
||
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog | ||
|
||
lockfile=/var/lock/subsys/$prog | ||
|
||
start() { | ||
[ -x $exec ] || exit 5 | ||
#[ -f $config ] || exit 6 | ||
echo -n $"Starting $prog: " | ||
# if not running, start it up here, usually something like "daemon $exec" | ||
daemon {{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ dockerhost_cadvisor_config_docker_endpoint }}" --listen_ip="{{ dockerhost_cadvisor_config_listen_interface }}" --port="{{ dockerhost_cadvisor_config_listen_port }}" {% for flag, flag_value in dockerhost_cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} | ||
echo | ||
[ $retval -eq 0 ] && touch $lockfile | ||
return $retval | ||
} | ||
|
||
stop() { | ||
echo -n $"Stopping $prog: " | ||
# stop it here, often "killproc $prog" | ||
killproc /opt/prometheus/exporters/cadvisor_current/cadvisor | ||
retval=$? | ||
echo | ||
[ $retval -eq 0 ] && rm -f $lockfile | ||
return $retval | ||
} | ||
|
||
restart() { | ||
stop | ||
start | ||
} | ||
|
||
reload() { | ||
restart | ||
} | ||
|
||
force_reload() { | ||
restart | ||
} | ||
|
||
rh_status() { | ||
# run checks to determine if the service is running or use generic status | ||
status $prog | ||
} | ||
|
||
rh_status_q() { | ||
rh_status >/dev/null 2>&1 | ||
} | ||
|
||
|
||
case "$1" in | ||
start) | ||
rh_status_q && exit 0 | ||
$1 | ||
;; | ||
stop) | ||
rh_status_q || exit 0 | ||
$1 | ||
;; | ||
restart) | ||
$1 | ||
;; | ||
reload) | ||
rh_status_q || exit 7 | ||
$1 | ||
;; | ||
force-reload) | ||
force_reload | ||
;; | ||
status) | ||
rh_status | ||
;; | ||
condrestart|try-restart) | ||
rh_status_q || exit 0 | ||
restart | ||
;; | ||
*) | ||
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | ||
exit 2 | ||
esac | ||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description=cadvisor | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
User=root | ||
Group=root | ||
ExecStart={{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ dockerhost_cadvisor_config_docker_endpoint }}" --listen_ip="{{ dockerhost_cadvisor_config_listen_interface }}" --port="{{ dockerhost_cadvisor_config_listen_port }}" {% for flag, flag_value in dockerhost_cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} | ||
|
||
SyslogIdentifier=cadvisor | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
description "cadvisor" | ||
start on (local-filesystems and net-device-up IFACE!=lo) | ||
stop on runlevel [016] | ||
|
||
respawn | ||
{% if upstart_version.stdout | replace("init (upstart ", "") |replace(")","") | version_compare('1.4', '>=') %} | ||
setuid root | ||
setgid root | ||
{% endif %} | ||
|
||
script | ||
exec >> "{{ dockerhost_prometheus_exporters_common_log_dir }}/cadvisor.log" | ||
exec 2>&1 | ||
exec {{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ dockerhost_cadvisor_config_docker_endpoint }}" --listen_ip="{{ dockerhost_cadvisor_config_listen_interface }}" --port="{{ dockerhost_cadvisor_config_listen_port }}" {% for flag, flag_value in dockerhost_cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} | ||
|
||
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ dockerhost_daemon_config | to_nice_json }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters