2014-05-06 11:52:03 -04:00
|
|
|
StatsD = require('lynx')
|
|
|
|
statsd = new StatsD('localhost', 8125, {on_error:->})
|
|
|
|
|
|
|
|
name = "unknown"
|
2014-05-07 05:58:52 -04:00
|
|
|
hostname = require('os').hostname()
|
2014-05-06 11:52:03 -04:00
|
|
|
|
2014-05-07 05:58:52 -04:00
|
|
|
buildKey = (key)-> "#{name}.#{hostname}.#{key}"
|
2014-05-06 11:52:03 -04:00
|
|
|
|
|
|
|
module.exports =
|
2014-05-06 12:33:09 -04:00
|
|
|
initialize: (_name) ->
|
|
|
|
name = _name
|
2014-05-06 11:52:03 -04:00
|
|
|
|
|
|
|
set : (key, value, sampleRate = 1)->
|
|
|
|
statsd.set buildKey(key), value, sampleRate
|
|
|
|
|
|
|
|
inc : (key, sampleRate = 1)->
|
|
|
|
statsd.increment buildKey(key), sampleRate
|
|
|
|
|
|
|
|
timing: (key, timeSpan, sampleRate)->
|
2014-05-07 06:08:46 -04:00
|
|
|
statsd.timing(buildKey(key), timeSpan, sampleRate)
|
2014-05-06 11:52:03 -04:00
|
|
|
|
|
|
|
Timer : class
|
|
|
|
constructor :(key, sampleRate = 1)->
|
|
|
|
this.start = new Date()
|
2014-05-07 06:08:46 -04:00
|
|
|
this.key = key
|
2014-05-06 11:52:03 -04:00
|
|
|
this.sampleRate = sampleRate
|
|
|
|
done:->
|
|
|
|
timeSpan = new Date - this.start
|
2014-05-07 06:43:46 -04:00
|
|
|
statsd.timing(buildKey(this.key), timeSpan, this.sampleRate)
|
2014-05-06 11:52:03 -04:00
|
|
|
|
|
|
|
gauge : (key, value, sampleRate = 1)->
|
|
|
|
statsd.gauge key, value, sampleRate
|
|
|
|
|
|
|
|
mongodb: require "./mongodb"
|
2014-05-07 05:58:52 -04:00
|
|
|
http: require "./http"
|
2014-05-06 11:52:03 -04:00
|
|
|
|