mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 04:03:34 -05:00
9329249bc9
This reverts commit fc2e043b20204e04f240814d4efc05762db7df96. Had to revert this because req.route.path is not set until a matching route has been hit, so it was always null inside res.end meaning statsd data was never sent over. This commit did not actually stop the memory leak so reverting it has not short term repocusion
31 lines
989 B
CoffeeScript
31 lines
989 B
CoffeeScript
os = require("os")
|
|
|
|
module.exports.monitor = (logger) ->
|
|
return (req, res, next) ->
|
|
Metrics = require("./metrics")
|
|
startTime = new Date()
|
|
end = res.end
|
|
res.end = () ->
|
|
end.apply(this, arguments)
|
|
responseTime = new Date() - startTime
|
|
if req.route?.path?
|
|
routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1)
|
|
key = "http-requests.#{routePath}.#{req.method}.#{res.statusCode}"
|
|
|
|
Metrics.timing(key, responseTime)
|
|
logger.log
|
|
req:
|
|
url: req.originalUrl || req.url
|
|
method: req.method
|
|
referrer: req.headers['referer'] || req.headers['referrer']
|
|
"remote-addr": req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress
|
|
"user-agent": req.headers["user-agent"]
|
|
"content-length": req.headers["content-length"]
|
|
res:
|
|
"content-length": res._headers?["content-length"]
|
|
statusCode: res.statusCode
|
|
"response-time": responseTime
|
|
"http request"
|
|
|
|
next()
|
|
|