mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 04:11:01 +00:00
30070f23b8
closes the statsd connection and cancels registered interval timers prevents express from hanging when trying to shutdown
46 lines
1 KiB
CoffeeScript
46 lines
1 KiB
CoffeeScript
StatsD = require('lynx')
|
|
statsd = new StatsD('localhost', 8125, {on_error:->})
|
|
|
|
name = "unknown"
|
|
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
|
|
|
|
inc : (key, sampleRate = 1)->
|
|
statsd.increment buildKey(key), sampleRate
|
|
|
|
timing: (key, timeSpan, sampleRate)->
|
|
statsd.timing(buildKey(key), timeSpan, sampleRate)
|
|
|
|
Timer : class
|
|
constructor :(key, sampleRate = 1)->
|
|
this.start = new Date()
|
|
this.key = key
|
|
this.sampleRate = sampleRate
|
|
done:->
|
|
timeSpan = new Date - this.start
|
|
statsd.timing(buildKey(this.key), timeSpan, this.sampleRate)
|
|
|
|
gauge : (key, value, sampleRate = 1)->
|
|
statsd.gauge buildKey(key), value, sampleRate
|
|
|
|
mongodb: require "./mongodb"
|
|
http: require "./http"
|
|
open_sockets: require "./open_sockets"
|
|
|
|
close: () ->
|
|
for func in destructors
|
|
func()
|
|
statsd.close()
|