Skip to content
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
29 changes: 29 additions & 0 deletions lib/container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,40 @@ container::_start_cadvisor_container() {
fi
}

container::_start_node_exporter_container() {
local name="prom/node-exporter"
local version="0.12.0"

log::info "Starting ${name}:${version} container"
local docker_logs
docker_logs=$(docker run \
--name=node-exporter \
--detach=true \
--restart=always \
--net=host \
--memory=100mb \
--memory-reservation=50mb \
"${name}:${version}" \
--collectors.enabled=conntrack,diskstats,filefd,filesystem,loadavg,meminfo,netdev,netstat,stat,time \
--web.listen-address=:29006)

if [[ "$?" -gt "0" ]]; then
local data='{"version":'"${version}"', "output":'"${docker_logs}"'}'
rollbar::report_error \
"Dock-Init: Cannot Run ${name} Container" \
"Starting ${name} Container is failing." \
"${data}"
return 1
fi
}

# Starts all container services needed for the dock
container::start() {
log::info "Starting container services"
backoff container::_start_registry_container
backoff container::_start_cadvisor_container
backoff container::_start_node_exporter_container

# swarm should be started last so we know everything is up
backoff container::_start_swarm_container
}
Expand Down
29 changes: 29 additions & 0 deletions test/container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,48 @@ describe 'container.sh'
rollbar::report_error::restore
end # end container::_start_cadvisor_container

describe 'container::_start_node_exporter_container'
local cadvisor_version='v0.24.1'
stub docker
stub rollbar::report_error

it 'should run docker container'
container::_start_node_exporter_container
docker::called
end

it 'should report errors on failure'
docker::errors
container::_start_node_exporter_container
rollbar::report_error::called
end

it 'should return 1 on failure'
docker::errors
container::_start_node_exporter_container
assert equal "$?" "1"
end

docker::restore
rollbar::report_error::restore
end # end container::_start_node_exporter_container

describe 'container::start'
stub container::_start_registry_container
stub container::_start_cadvisor_container
stub container::_start_node_exporter_container
stub container::_start_swarm_container

it 'should start all required containers'
container::start
container::_start_registry_container::called
container::_start_cadvisor_container::called
container::_start_node_exporter_container::called
container::_start_swarm_container::called

container::_start_registry_container::restore
container::_start_cadvisor_container::restore
container::_start_node_exporter_container::restore
container::_start_swarm_container::restore
end # end container::start
end # container.sh