mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 04:41:01 +00:00
35 lines
844 B
CoffeeScript
35 lines
844 B
CoffeeScript
|
StatsD = require('lynx')
|
||
|
statsd = new StatsD('localhost', 8125, {on_error:->})
|
||
|
|
||
|
name = "unknown"
|
||
|
|
||
|
buildKey = (key)-> "#{name}.#{process.env.NODE_ENV or "development"}.#{key}"
|
||
|
|
||
|
module.exports =
|
||
|
initialize: (options = {}) ->
|
||
|
name = options.name
|
||
|
|
||
|
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(key, timeSpan, sampleRate)
|
||
|
|
||
|
Timer : class
|
||
|
constructor :(key, sampleRate = 1)->
|
||
|
this.start = new Date()
|
||
|
this.key = buildKey(key)
|
||
|
this.sampleRate = sampleRate
|
||
|
done:->
|
||
|
timeSpan = new Date - this.start
|
||
|
statsd.timing(this.key, timeSpan, this.sampleRate)
|
||
|
|
||
|
gauge : (key, value, sampleRate = 1)->
|
||
|
statsd.gauge key, value, sampleRate
|
||
|
|
||
|
mongodb: require "./mongodb"
|
||
|
|