Merge pull request #2 from sharelatex/clean-shutdown

Clean shutdown
This commit is contained in:
James Allen 2015-01-06 14:03:49 +00:00
commit 1816676e5c
3 changed files with 14 additions and 2 deletions

View file

@ -6,10 +6,15 @@ hostname = require('os').hostname()
buildKey = (key)-> "#{name}.#{hostname}.#{key}"
destructors = []
module.exports =
initialize: (_name) ->
name = _name
registerDestructor: (func) ->
destructors.push func
set : (key, value, sampleRate = 1)->
statsd.set buildKey(key), value, sampleRate
@ -35,3 +40,7 @@ module.exports =
http: require "./http"
open_sockets: require "./open_sockets"
close: () ->
for func in destructors
func()
statsd.close()

View file

@ -3,9 +3,12 @@ seconds = 1000
module.exports = OpenSocketsMonitor =
monitor: (logger) ->
setInterval () ->
interval = setInterval () ->
OpenSocketsMonitor.gaugeOpenSockets()
, 5 * seconds
Metrics = require "./metrics"
Metrics.registerDestructor () ->
clearInterval(interval)
gaugeOpenSockets: () ->
Metrics = require "./metrics"

View file

@ -1,6 +1,6 @@
{
"name": "metrics-sharelatex",
"version": "1.0.0",
"version": "1.1.0",
"description": "A drop-in metrics and monitoring module for node.js apps",
"repository": {
"type": "git",