From d27a1ced364f0d070e38608093fe84e806f79f5d Mon Sep 17 00:00:00 2001 From: Anandkumar Patel Date: Fri, 4 Nov 2016 15:09:18 -0700 Subject: [PATCH 1/3] add node-exporter --- lib/container.sh | 28 ++++++++++++++++++++++++++++ test/container.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/lib/container.sh b/lib/container.sh index 3ac5e6a..f30468c 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -101,11 +101,39 @@ 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 + --publish=29006:9100 \ + --memory=100mb \ + --memory-reservation=50mb \ + "${name}:${version}") + + 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 From caab85d69242b9e1a2f488c7a359f169aaf23056 Mon Sep 17 00:00:00 2001 From: Anandkumar Patel Date: Fri, 4 Nov 2016 15:14:33 -0700 Subject: [PATCH 2/3] add missing \ --- lib/container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/container.sh b/lib/container.sh index f30468c..6d0b92c 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -111,7 +111,7 @@ container::_start_node_exporter_container() { --name=node-exporter \ --detach=true \ --restart=always \ - --net=host + --net=host \ --publish=29006:9100 \ --memory=100mb \ --memory-reservation=50mb \ From 9d113a98531558d68e27d5a7eade8ab93385ea6e Mon Sep 17 00:00:00 2001 From: Anandkumar Patel Date: Fri, 4 Nov 2016 17:58:05 -0700 Subject: [PATCH 3/3] remove port, add specific collectors --- lib/container.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/container.sh b/lib/container.sh index 6d0b92c..093a336 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -112,10 +112,11 @@ container::_start_node_exporter_container() { --detach=true \ --restart=always \ --net=host \ - --publish=29006:9100 \ --memory=100mb \ --memory-reservation=50mb \ - "${name}:${version}") + "${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}"'}'