mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
30070f23b8
closes the statsd connection and cancels registered interval timers prevents express from hanging when trying to shutdown
22 lines
757 B
CoffeeScript
22 lines
757 B
CoffeeScript
URL = require "url"
|
|
seconds = 1000
|
|
|
|
module.exports = OpenSocketsMonitor =
|
|
monitor: (logger) ->
|
|
interval = setInterval () ->
|
|
OpenSocketsMonitor.gaugeOpenSockets()
|
|
, 5 * seconds
|
|
Metrics = require "./metrics"
|
|
Metrics.registerDestructor () ->
|
|
clearInterval(interval)
|
|
|
|
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
|