Skip to content

Commit 2919226

Browse files
use start/stop stype
1 parent 69781b5 commit 2919226

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Api.prototype.start = function (cb) {
2424
// start github ssh key generator
2525
keyGen.start();
2626
// start sending socket count
27-
dogstatsd.captureSocketCount();
27+
dogstatsd.monitorStart();
2828

2929
var count = createCount(callback);
3030
// connect to mongoose
@@ -69,6 +69,8 @@ Api.prototype.stop = function (cb) {
6969
var count = createCount(cb);
7070
// stop github ssh key generator
7171
keyGen.stop();
72+
// stop sending socket count
73+
dogstatsd.monitorStart();
7274
// express server
7375
mongooseControl.stop(count.inc().next);
7476
events.close(count.inc().next);

configs/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ POLL_MONGO_TIMEOUT="30 minutes"
4444
GITHUB_SCOPE="user:email,repo,repo_deployment,read:repo_hook"
4545
GITHUB_HOOK_SECRET="3V3RYTHINGisAW3S0ME!"
4646
DOCKER_IMAGE_BUILDER_CACHE="/git-cache"
47+
MONITOR_INTERVAL="1 minute"

lib/models/datadog/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,22 @@ function captureSocketCount () {
3939
if (err) { return; }
4040
client.gauge('api.openFiles', parseInt(stdout), 1, ['pid:'+process.pid]);
4141
});
42-
setTimeout(captureSocketCount, 60000);
42+
}
43+
44+
var interval;
45+
46+
function monitorStart () {
47+
if (interval) { return; }
48+
interval = setInterval(captureSocketCount, process.env.MONITOR_INTERVAL);
49+
}
50+
51+
function monitorStop () {
52+
if (interval) {
53+
clearInterval(interval);
54+
interval = null;
55+
}
4356
}
4457

4558
module.exports.captureSteamData = captureSteamData;
46-
module.exports.captureSocketCount = captureSocketCount;
59+
module.exports.monitorStart = monitorStart;
60+
module.exports.monitorStop = monitorStop;

0 commit comments

Comments
 (0)