Skip to content

Commit 526a339

Browse files
add num files and socket monitoring
1 parent ef2b21e commit 526a339

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/express-app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ app.use(require('connect-datadog')({
1616
'method':true,
1717
'tags': ['name:api', 'logType:express', 'env:'+process.env.NODE_ENV]
1818
}));
19+
app.use(dogstatsd.captureSocketCount);
1920

2021
if (envIs('development', 'local', 'io')) {
2122
app.use(morganFreeman());

lib/models/datadog/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var StatsD = require('node-dogstatsd').StatsD;
33
var client = module.exports = new StatsD(
44
process.env.DATADOG_HOST,
55
process.env.DATADOG_PORT);
6-
6+
var exec = require('child_process').exec;
77

88
function captureSteamData (streamName, stream) {
99
stream.on('data', function(){
@@ -21,5 +21,26 @@ function captureSteamData (streamName, stream) {
2121
}
2222

2323

24+
function captureSocketCount (req, res, next) {
25+
var sockets = require('http').globalAgent.sockets;
26+
var request = require('http').globalAgent.requests;
27+
var key;
28+
29+
for (key in sockets) {
30+
client.gauge('sockets_open', sockets[key].length, ['target:'+key]);
31+
}
32+
33+
for (key in request) {
34+
client.gauge('sockets_pending', request[key].length, ['target:'+key]);
35+
}
36+
37+
exec('lsof -p ' + process.pid + ' | wc -l', function (err, stdout) {
38+
if (err) { return; }
39+
client.gauge('openFiles', parseInt(stdout), ['target:'+key]);
40+
});
41+
42+
next();
43+
}
2444

2545
module.exports.captureSteamData = captureSteamData;
46+
module.exports.captureSocketCount = captureSocketCount;

0 commit comments

Comments
 (0)