open_sockets.coffee 652 B

12345678910111213141516171819
  1. URL = require "url"
  2. seconds = 1000
  3. module.exports = OpenSocketsMonitor =
  4. monitor: (logger) ->
  5. setInterval () ->
  6. OpenSocketsMonitor.gaugeOpenSockets()
  7. , 5 * seconds
  8. gaugeOpenSockets: () ->
  9. Metrics = require "./metrics"
  10. for url, agents of require('http').globalAgent.sockets
  11. url = URL.parse("http://#{url}")
  12. hostname = url.hostname?.replace(/\./g, "_")
  13. Metrics.gauge "open_connections.http.#{hostname}", agents.length
  14. for url, agents of require('https').globalAgent.sockets
  15. url = URL.parse("https://#{url}")
  16. hostname = url.hostname?.replace(/\./g, "_")
  17. Metrics.gauge "open_connections.https.#{hostname}", agents.length