File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
2021if ( envIs ( 'development' , 'local' , 'io' ) ) {
2122 app . use ( morganFreeman ( ) ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ var StatsD = require('node-dogstatsd').StatsD;
33var client = module . exports = new StatsD (
44 process . env . DATADOG_HOST ,
55 process . env . DATADOG_PORT ) ;
6-
6+ var exec = require ( 'child_process' ) . exec ;
77
88function 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
2545module . exports . captureSteamData = captureSteamData ;
46+ module . exports . captureSocketCount = captureSocketCount ;
You can’t perform that action at this time.
0 commit comments