Просмотр исходного кода

improve mongo metrics to be more promethious like

Henry Oswald 7 лет назад
Родитель
Сommit
b9f3a3f987

+ 1 - 1
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("http_request", responseTime, null, {method:req.method, status_code:res.status_code, path:routePath})
+				Metrics.timing("http_request", responseTime, null, {method:req.method, status_code: res.statusCode, path:routePath})
 				logger.log
 					req:
 						url: req.originalUrl || req.url

+ 4 - 4
libraries/metrics/metrics.coffee

@@ -87,22 +87,22 @@ module.exports = Metrics =
 				help: key,
 				maxAgeSeconds: 600,
 				ageBuckets: 10,
-				labelNames: ['app', 'path', 'status_code', 'method']
+				labelNames: ['app', 'path', 'status_code', 'method', 'collection', 'query']
 			})
 		opts.app = name
-		console.log(key, opts, "timing key")
 		promMetrics[key].observe(opts, timeSpan)
 
 	Timer : class
-		constructor :(key, sampleRate = 1)->
+		constructor :(key, sampleRate = 1, opts)->
 			this.start = new Date()
 			key = Metrics.sanitizeKey(key)
 			this.key = key
 			this.sampleRate = sampleRate
+			this.opts = opts
 
 		done:->
 			timeSpan = new Date - this.start
-			Metrics.timing(this.key, timeSpan, this.sampleRate)
+			Metrics.timing(this.key, timeSpan, this.sampleRate, this.opts)
 			return timeSpan
 
 	gauge : (key, value, sampleRate = 1)->

+ 1 - 1
libraries/metrics/mongodb.coffee

@@ -34,7 +34,7 @@ module.exports =
 					query = Object.keys(db_command.query).sort().join("_")
 					key += "." + query
 
-				timer = new Metrics.Timer(key)
+				timer = new Metrics.Timer("mongo", {collection: collection, query:query})
 				start = new Date()
 				_method.call this, db_command, options, () ->
 					timer.done()

+ 1 - 1
libraries/metrics/timeAsyncMethod.coffee

@@ -17,7 +17,7 @@ module.exports = (obj, methodName, prefix, logger) ->
 				logger.log "[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback"
 			return realMethod.apply this, originalArgs
 
-		timer = new metrics.Timer(key)
+		timer = new metrics.Timer(prefix, null, {method: methodName})
 
 		realMethod.call this, firstArgs..., (callbackArgs...) ->
 			elapsedTime = timer.done()