Skip to content

Commit 0185ce7

Browse files
Merge pull request #40 from CodeNow/SAN-5334-add-node-exporter
San 5334 add node exporter
2 parents 0578250 + 9d113a9 commit 0185ce7

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

lib/container.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,40 @@ container::_start_cadvisor_container() {
101101
fi
102102
}
103103

104+
container::_start_node_exporter_container() {
105+
local name="prom/node-exporter"
106+
local version="0.12.0"
107+
108+
log::info "Starting ${name}:${version} container"
109+
local docker_logs
110+
docker_logs=$(docker run \
111+
--name=node-exporter \
112+
--detach=true \
113+
--restart=always \
114+
--net=host \
115+
--memory=100mb \
116+
--memory-reservation=50mb \
117+
"${name}:${version}" \
118+
--collectors.enabled=conntrack,diskstats,filefd,filesystem,loadavg,meminfo,netdev,netstat,stat,time \
119+
--web.listen-address=:29006)
120+
121+
if [[ "$?" -gt "0" ]]; then
122+
local data='{"version":'"${version}"', "output":'"${docker_logs}"'}'
123+
rollbar::report_error \
124+
"Dock-Init: Cannot Run ${name} Container" \
125+
"Starting ${name} Container is failing." \
126+
"${data}"
127+
return 1
128+
fi
129+
}
130+
104131
# Starts all container services needed for the dock
105132
container::start() {
106133
log::info "Starting container services"
107134
backoff container::_start_registry_container
108135
backoff container::_start_cadvisor_container
136+
backoff container::_start_node_exporter_container
137+
109138
# swarm should be started last so we know everything is up
110139
backoff container::_start_swarm_container
111140
}

test/container.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,48 @@ describe 'container.sh'
109109
rollbar::report_error::restore
110110
end # end container::_start_cadvisor_container
111111

112+
describe 'container::_start_node_exporter_container'
113+
local cadvisor_version='v0.24.1'
114+
stub docker
115+
stub rollbar::report_error
116+
117+
it 'should run docker container'
118+
container::_start_node_exporter_container
119+
docker::called
120+
end
121+
122+
it 'should report errors on failure'
123+
docker::errors
124+
container::_start_node_exporter_container
125+
rollbar::report_error::called
126+
end
127+
128+
it 'should return 1 on failure'
129+
docker::errors
130+
container::_start_node_exporter_container
131+
assert equal "$?" "1"
132+
end
133+
134+
docker::restore
135+
rollbar::report_error::restore
136+
end # end container::_start_node_exporter_container
137+
112138
describe 'container::start'
113139
stub container::_start_registry_container
114140
stub container::_start_cadvisor_container
141+
stub container::_start_node_exporter_container
115142
stub container::_start_swarm_container
116143

117144
it 'should start all required containers'
118145
container::start
119146
container::_start_registry_container::called
120147
container::_start_cadvisor_container::called
148+
container::_start_node_exporter_container::called
121149
container::_start_swarm_container::called
122150

123151
container::_start_registry_container::restore
124152
container::_start_cadvisor_container::restore
153+
container::_start_node_exporter_container::restore
125154
container::_start_swarm_container::restore
126155
end # end container::start
127156
end # container.sh

0 commit comments

Comments
 (0)