@@ -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 ( 'api.sockets_open' , sockets [ key ] . length , 1 , [ 'target:' + key ] ) ;
31+ }
32+
33+ for ( key in request ) {
34+ client . gauge ( 'api.sockets_pending' , request [ key ] . length , 1 , [ 'target:' + key ] ) ;
35+ }
36+
37+ exec ( 'lsof -p ' + process . pid + ' | wc -l' , function ( err , stdout ) {
38+ if ( err ) { return ; }
39+ client . gauge ( 'api.openFiles' , parseInt ( stdout ) , 1 , [ 'target:' + key ] ) ;
40+ } ) ;
41+
42+ next ( ) ;
43+ }
2444
2545module . exports . captureSteamData = captureSteamData ;
46+ module . exports . captureSocketCount = captureSocketCount ;
0 commit comments