2014-05-09 08:30:12 -04:00
|
|
|
URL = require "url"
|
|
|
|
seconds = 1000
|
|
|
|
|
2015-08-31 09:02:03 -04:00
|
|
|
# In Node 0.10 the default is 5, which means only 5 open connections at one.
|
|
|
|
# Node 0.12 has a default of Infinity. Make sure we have no limit set,
|
|
|
|
# regardless of Node version.
|
|
|
|
require("http").globalAgent.maxSockets = Infinity
|
|
|
|
require("https").globalAgent.maxSockets = Infinity
|
|
|
|
|
2014-05-09 08:30:12 -04:00
|
|
|
module.exports = OpenSocketsMonitor =
|
|
|
|
monitor: (logger) ->
|
2015-01-05 11:45:32 -05:00
|
|
|
interval = setInterval () ->
|
2014-05-09 08:30:12 -04:00
|
|
|
OpenSocketsMonitor.gaugeOpenSockets()
|
|
|
|
, 5 * seconds
|
2015-01-05 11:45:32 -05:00
|
|
|
Metrics = require "./metrics"
|
|
|
|
Metrics.registerDestructor () ->
|
|
|
|
clearInterval(interval)
|
2014-05-09 08:30:12 -04:00
|
|
|
|
|
|
|
gaugeOpenSockets: () ->
|
|
|
|
Metrics = require "./metrics"
|
|
|
|
for url, agents of require('http').globalAgent.sockets
|
|
|
|
url = URL.parse("http://#{url}")
|
|
|
|
hostname = url.hostname?.replace(/\./g, "_")
|
|
|
|
Metrics.gauge "open_connections.http.#{hostname}", agents.length
|
|
|
|
for url, agents of require('https').globalAgent.sockets
|
|
|
|
url = URL.parse("https://#{url}")
|
|
|
|
hostname = url.hostname?.replace(/\./g, "_")
|
|
|
|
Metrics.gauge "open_connections.https.#{hostname}", agents.length
|