2014-05-06 15:52:03 +00:00
|
|
|
StatsD = require('lynx')
|
|
|
|
statsd = new StatsD('localhost', 8125, {on_error:->})
|
|
|
|
|
|
|
|
name = "unknown"
|
2014-05-07 09:58:52 +00:00
|
|
|
hostname = require('os').hostname()
|
2014-05-06 15:52:03 +00:00
|
|
|
|
2014-05-07 09:58:52 +00:00
|
|
|
buildKey = (key)-> "#{name}.#{hostname}.#{key}"
|
2014-05-06 15:52:03 +00:00
|
|
|
|
2015-01-05 16:45:32 +00:00
|
|
|
destructors = []
|
|
|
|
|
2016-10-24 09:50:44 +00:00
|
|
|
require "./uv_threadpool_size"
|
|
|
|
|
2017-03-15 15:06:54 +00:00
|
|
|
module.exports = Metrics =
|
2014-05-06 16:33:09 +00:00
|
|
|
initialize: (_name) ->
|
|
|
|
name = _name
|
2014-05-06 15:52:03 +00:00
|
|
|
|
2015-01-05 16:45:32 +00:00
|
|
|
registerDestructor: (func) ->
|
|
|
|
destructors.push func
|
|
|
|
|
2014-05-06 15:52:03 +00:00
|
|
|
set : (key, value, sampleRate = 1)->
|
|
|
|
statsd.set buildKey(key), value, sampleRate
|
|
|
|
|
|
|
|
inc : (key, sampleRate = 1)->
|
|
|
|
statsd.increment buildKey(key), sampleRate
|
|
|
|
|
2016-03-15 13:52:32 +00:00
|
|
|
count : (key, count, sampleRate = 1)->
|
|
|
|
statsd.count buildKey(key), count, sampleRate
|
|
|
|
|
2014-05-06 15:52:03 +00:00
|
|
|
timing: (key, timeSpan, sampleRate)->
|
2014-05-07 10:08:46 +00:00
|
|
|
statsd.timing(buildKey(key), timeSpan, sampleRate)
|
2014-05-06 15:52:03 +00:00
|
|
|
|
|
|
|
Timer : class
|
|
|
|
constructor :(key, sampleRate = 1)->
|
|
|
|
this.start = new Date()
|
2014-05-07 10:08:46 +00:00
|
|
|
this.key = key
|
2014-05-06 15:52:03 +00:00
|
|
|
this.sampleRate = sampleRate
|
|
|
|
done:->
|
|
|
|
timeSpan = new Date - this.start
|
2014-05-07 10:43:46 +00:00
|
|
|
statsd.timing(buildKey(this.key), timeSpan, this.sampleRate)
|
2016-03-15 13:52:40 +00:00
|
|
|
return timeSpan
|
2014-05-06 15:52:03 +00:00
|
|
|
|
|
|
|
gauge : (key, value, sampleRate = 1)->
|
2014-05-09 12:54:33 +00:00
|
|
|
statsd.gauge buildKey(key), value, sampleRate
|
2014-05-06 15:52:03 +00:00
|
|
|
|
|
|
|
mongodb: require "./mongodb"
|
2014-05-07 09:58:52 +00:00
|
|
|
http: require "./http"
|
2014-05-09 12:30:12 +00:00
|
|
|
open_sockets: require "./open_sockets"
|
2015-06-23 09:51:48 +00:00
|
|
|
event_loop: require "./event_loop"
|
2015-08-13 15:13:09 +00:00
|
|
|
memory: require "./memory"
|
2014-05-06 15:52:03 +00:00
|
|
|
|
2017-03-15 15:06:54 +00:00
|
|
|
timeAsyncMethod: require('./timeAsyncMethod')
|
|
|
|
|
2015-01-05 16:45:32 +00:00
|
|
|
close: () ->
|
|
|
|
for func in destructors
|
|
|
|
func()
|
|
|
|
statsd.close()
|