mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
improve mongo metrics to be more promethious like
This commit is contained in:
parent
4806e6fd87
commit
b9f3a3f987
4 changed files with 7 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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)->
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue