From 00c0036ca5f0a333f315aab584e500f4c3b2d39a Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 9 May 2014 13:30:12 +0100 Subject: [PATCH] Add open socket monitoring --- libraries/metrics/metrics.coffee | 1 + libraries/metrics/open_sockets.coffee | 19 +++++++++++++++++++ libraries/metrics/package.json | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 libraries/metrics/open_sockets.coffee diff --git a/libraries/metrics/metrics.coffee b/libraries/metrics/metrics.coffee index 0e6e9908f6..2b3c418046 100644 --- a/libraries/metrics/metrics.coffee +++ b/libraries/metrics/metrics.coffee @@ -33,4 +33,5 @@ module.exports = mongodb: require "./mongodb" http: require "./http" + open_sockets: require "./open_sockets" diff --git a/libraries/metrics/open_sockets.coffee b/libraries/metrics/open_sockets.coffee new file mode 100644 index 0000000000..d74a781496 --- /dev/null +++ b/libraries/metrics/open_sockets.coffee @@ -0,0 +1,19 @@ +URL = require "url" +seconds = 1000 + +module.exports = OpenSocketsMonitor = + monitor: (logger) -> + setInterval () -> + OpenSocketsMonitor.gaugeOpenSockets() + , 5 * seconds + + 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 diff --git a/libraries/metrics/package.json b/libraries/metrics/package.json index a76929f2fa..23d2d2ae75 100644 --- a/libraries/metrics/package.json +++ b/libraries/metrics/package.json @@ -4,7 +4,7 @@ "description": "A drop-in metrics and monitoring module for node.js apps", "dependencies": { "lynx": "~0.1.1", - "coffee-script": "~1.7.1", + "coffee-script": "1.6.0", "underscore": "~1.6.0" } }