From 4806e6fd87cda661fd21e2fd0b37bb75efc36ea0 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 23 Nov 2018 16:24:31 +0000 Subject: [PATCH] use lables --- libraries/metrics/http.coffee | 2 +- libraries/metrics/metrics.coffee | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libraries/metrics/http.coffee b/libraries/metrics/http.coffee index c175f26a14..1abaede902 100644 --- a/libraries/metrics/http.coffee +++ b/libraries/metrics/http.coffee @@ -12,7 +12,7 @@ module.exports.monitor = (logger) -> routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1) key = "http-requests.#{routePath}.#{req.method}.#{res.statusCode}" - Metrics.timing(key, responseTime) + Metrics.timing("http_request", responseTime, null, {method:req.method, status_code:res.status_code, path:routePath}) logger.log req: url: req.originalUrl || req.url diff --git a/libraries/metrics/metrics.coffee b/libraries/metrics/metrics.coffee index 908efb6caf..60624e4ac2 100644 --- a/libraries/metrics/metrics.coffee +++ b/libraries/metrics/metrics.coffee @@ -78,17 +78,20 @@ module.exports = Metrics = }) promMetrics[key].inc({name: name, host: hostname}, count) - timing: (key, timeSpan, sampleRate)-> + timing: (key, timeSpan, sampleRate, opts = {})-> statsd.timing(buildKey(key), timeSpan, sampleRate) - key = Metrics.buildPromKey("timer_#{key}") + key = Metrics.sanitizeKey("timer_" + key) if !promMetrics[key]? promMetrics[key] = new prom.Summary({ name: key, help: key, maxAgeSeconds: 600, - ageBuckets: 10 + ageBuckets: 10, + labelNames: ['app', 'path', 'status_code', 'method'] }) - promMetrics[key].observe(timeSpan) + opts.app = name + console.log(key, opts, "timing key") + promMetrics[key].observe(opts, timeSpan) Timer : class constructor :(key, sampleRate = 1)-> @@ -109,9 +112,9 @@ module.exports = Metrics = promMetrics[key] = new prom.Gauge({ name: key, help: key, - labelNames: ['name','host'] + labelNames: ['app','host'] }) - promMetrics[key].set({name: name, host: hostname}, this.sanitizeValue(value)) + promMetrics[key].set({app: name, host: hostname}, this.sanitizeValue(value)) globalGauge: (key, value, sampleRate = 1)-> statsd.gauge buildGlobalKey(key), value, sampleRate @@ -120,9 +123,9 @@ module.exports = Metrics = promMetrics[key] = new prom.Gauge({ name: key, help: key, - labelNames: ['name','host'] + labelNames: ['app','host'] }) - promMetrics[key].set({name: name},this.sanitizeValue(value)) + promMetrics[key].set({app: name},this.sanitizeValue(value)) mongodb: require "./mongodb" http: require "./http"