Skip to content

Commit

Permalink
Merge pull request #447 from CodeNow/bump-max-socket
Browse files Browse the repository at this point in the history
add socket and file monitoring
  • Loading branch information
anandkumarpatel committed Dec 29, 2014
2 parents e0d77c0 + ec08249 commit d73c55e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions configs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ HASHIDS_LENGTH=6
DOCKER_IMAGE_BUILDER_NAME="runnable/image-builder"
DOCKER_IMAGE_BUILDER_VERSION="d1.3.1-v1.4.3"
DOCKER_IMAGE_BUILDER_CACHE="/tmp"
DOCKER_TIMEOUT=5000
BUILD_END_TIMEOUT=100
DATADOG_HOST="localhost"
DATADOG_PORT=8125
Expand Down
24 changes: 12 additions & 12 deletions lib/express-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ var pkg = require('../package.json');
var dogstatsd = require('models/datadog');
var app = module.exports = express();

app.use(require('connect-datadog')({
'dogstatsd': dogstatsd,
'response_code':true,
'method':true,
'tags': ['name:api', 'logType:express', 'env:'+process.env.NODE_ENV]
}));
if (envIs('production')) {
app.use(require('connect-datadog')({
'dogstatsd': dogstatsd,
'response_code':true,
'method':true,
'tags': ['name:api', 'logType:express', 'env:'+process.env.NODE_ENV]
}));

if (envIs('development', 'local', 'io')) {
app.use(morganFreeman());
app.use(function (req, res, next) {
console.log(req.method, '-', req.url);
next();
});
app.use(dogstatsd.captureSocketCount);
}

if (envIs('development', 'local', 'stage')) {
app.use(morganFreeman('short'));
}

app.use(require('./routes/github'));
Expand Down
3 changes: 2 additions & 1 deletion lib/models/apis/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function Docker (dockerHost) {
this.port = parsed.port || 4243;
this.docker = dogerode(new Dockerode({
host: this.dockerHost,
port: this.port
port: this.port,
timeout: process.env.DOCKER_TIMEOUT
}), {
service: 'api',
host: process.env.DATADOG_HOST,
Expand Down
23 changes: 22 additions & 1 deletion lib/models/datadog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var StatsD = require('node-dogstatsd').StatsD;
var client = module.exports = new StatsD(
process.env.DATADOG_HOST,
process.env.DATADOG_PORT);

var exec = require('child_process').exec;

function captureSteamData (streamName, stream) {
stream.on('data', function(){
Expand All @@ -21,5 +21,26 @@ function captureSteamData (streamName, stream) {
}


function captureSocketCount (req, res, next) {
var sockets = require('http').globalAgent.sockets;
var request = require('http').globalAgent.requests;
var key;

for (key in sockets) {
client.gauge('api.sockets_open', sockets[key].length, 1, ['target:'+key]);
}

for (key in request) {
client.gauge('api.sockets_pending', request[key].length, 1, ['target:'+key]);
}

exec('lsof -p ' + process.pid + ' | wc -l', function (err, stdout) {
if (err) { return; }
client.gauge('api.openFiles', parseInt(stdout), 1, ['target:'+key]);
});

next();
}

module.exports.captureSteamData = captureSteamData;
module.exports.captureSocketCount = captureSocketCount;

0 comments on commit d73c55e

Please sign in to comment.