From 6d4d05957ea92c7d0276d4b4a30742abb9634098 Mon Sep 17 00:00:00 2001 From: Christopher Hoskin Date: Tue, 6 Nov 2018 14:22:03 +0000 Subject: [PATCH] Get counter metric working --- libraries/metrics/metrics.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/metrics/metrics.coffee b/libraries/metrics/metrics.coffee index d3468945a4..f40a0b3ee2 100644 --- a/libraries/metrics/metrics.coffee +++ b/libraries/metrics/metrics.coffee @@ -11,6 +11,8 @@ hostname = require('os').hostname() buildKey = (key)-> "#{name}.#{hostname}.#{key}" buildGlobalKey = (key)-> "#{name}.global.#{key}" +counters = {} + destructors = [] require "./uv_threadpool_size" @@ -34,6 +36,14 @@ module.exports = Metrics = inc : (key, sampleRate = 1)-> statsd.increment buildKey(key), sampleRate + if !counters[key] + console.log("No Metric") + counters[key] = new prom.Counter({ + name: key, + help: key #https://prometheus.io/docs/instrumenting/writing_exporters/#help-strings this is probably wrong + labelNames: ['name','host'] + }) + counters[key].inc({name: name, host: hostname}) count : (key, count, sampleRate = 1)-> statsd.count buildKey(key), count, sampleRate