overleaf/services/spelling/app/coffee/Metrics.coffee
2014-08-15 12:13:35 +01:00

23 lines
592 B
CoffeeScript

StatsD = require('node-statsd').StatsD
statsd = new StatsD('localhost',8125)
buildKey = (key)-> "spelling.#{process.env.NODE_ENV}.#{key}"
module.exports =
inc : (key, sampleRate)->
statsd.increment buildKey(key, sampleRate)
Timer : class
constructor :(key)->
this.start = new Date()
this.key = buildKey(key)
done:->
timeSpan = new Date - this.start
statsd.timing("#{this.key}-time", timeSpan)
statsd.increment "#{this.key}-count"
gauge : (key, value, sampleRate)->
stats = {};
stat = buildKey(key)
stats[stat] = value+"|g";
statsd.send(stats, sampleRate);