Get default Prometheus metrics working

This commit is contained in:
Christopher Hoskin 2018-11-06 11:14:26 +00:00
parent 31e97f92d5
commit f604fb92e5

View file

@ -1,6 +1,10 @@
StatsD = require('lynx')
statsd = new StatsD(process.env["STATSD_HOST"] or "localhost", 8125, {on_error:->})
prom = require('prom-client')
Register = require('prom-client').register
collectDefaultMetrics = prom.collectDefaultMetrics
name = "unknown"
hostname = require('os').hostname()
@ -14,10 +18,17 @@ require "./uv_threadpool_size"
module.exports = Metrics =
initialize: (_name) ->
name = _name
collectDefaultMetrics({ timeout: 5000, prefix: name })
registerDestructor: (func) ->
destructors.push func
injectMetricsRoute: (app) ->
app.get('/metrics', (req, res) ->
res.set('Content-Type', Register.contentType)
res.end(Register.metrics())
)
set : (key, value, sampleRate = 1)->
statsd.set buildKey(key), value, sampleRate