@@ -20,27 +20,41 @@ function captureSteamData (streamName, stream) {
2020 } ) ;
2121}
2222
23-
24- function captureSocketCount ( req , res , next ) {
23+ function captureSocketCount ( ) {
2524 var sockets = require ( 'http' ) . globalAgent . sockets ;
2625 var request = require ( 'http' ) . globalAgent . requests ;
2726 var key ;
2827
2928 for ( key in sockets ) {
30- client . gauge ( 'api.sockets_open' , sockets [ key ] . length , 1 , [ 'target:' + key ] ) ;
29+ client . gauge ( 'api.sockets_open' , sockets [ key ] . length , 1 ,
30+ [ 'target:' + key , 'pid:' + process . pid ] ) ;
3131 }
3232
3333 for ( key in request ) {
34- client . gauge ( 'api.sockets_pending' , request [ key ] . length , 1 , [ 'target:' + key ] ) ;
34+ client . gauge ( 'api.sockets_pending' , request [ key ] . length , 1 ,
35+ [ 'target:' + key , 'pid:' + process . pid ] ) ;
3536 }
3637
3738 exec ( 'lsof -p ' + process . pid + ' | wc -l' , function ( err , stdout ) {
3839 if ( err ) { return ; }
3940 client . gauge ( 'api.openFiles' , parseInt ( stdout ) , 1 , [ 'pid:' + process . pid ] ) ;
4041 } ) ;
42+ }
43+
44+ var interval ;
4145
42- next ( ) ;
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
4558module . exports . captureSteamData = captureSteamData ;
46- module . exports . captureSocketCount = captureSocketCount ;
59+ module . exports . monitorStart = monitorStart ;
60+ module . exports . monitorStop = monitorStop ;
0 commit comments