From f604fb92e5007dc5f8aebc9794f15f6d6ff99369 Mon Sep 17 00:00:00 2001 From: Christopher Hoskin Date: Tue, 6 Nov 2018 11:14:26 +0000 Subject: [PATCH] Get default Prometheus metrics working --- libraries/metrics/metrics.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/metrics/metrics.coffee b/libraries/metrics/metrics.coffee index e9a25966b5..d3468945a4 100644 --- a/libraries/metrics/metrics.coffee +++ b/libraries/metrics/metrics.coffee @@ -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