diff --git a/lib/container.sh b/lib/container.sh index 3ac5e6a..093a336 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -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 } diff --git a/test/container.sh b/test/container.sh index b5dbf09..597b393 100644 --- a/test/container.sh +++ b/test/container.sh @@ -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