mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add in http monitoring
This commit is contained in:
parent
4da7fa43fa
commit
f4895fb04f
2 changed files with 32 additions and 1 deletions
29
libraries/metrics/http.coffee
Normal file
29
libraries/metrics/http.coffee
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
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
|
||||||
|
routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1)
|
||||||
|
key = "#{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()
|
||||||
|
|
|
@ -2,8 +2,9 @@ StatsD = require('lynx')
|
||||||
statsd = new StatsD('localhost', 8125, {on_error:->})
|
statsd = new StatsD('localhost', 8125, {on_error:->})
|
||||||
|
|
||||||
name = "unknown"
|
name = "unknown"
|
||||||
|
hostname = require('os').hostname()
|
||||||
|
|
||||||
buildKey = (key)-> "#{name}.#{process.env.NODE_ENV or "development"}.#{key}"
|
buildKey = (key)-> "#{name}.#{hostname}.#{key}"
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
initialize: (_name) ->
|
initialize: (_name) ->
|
||||||
|
@ -31,4 +32,5 @@ module.exports =
|
||||||
statsd.gauge key, value, sampleRate
|
statsd.gauge key, value, sampleRate
|
||||||
|
|
||||||
mongodb: require "./mongodb"
|
mongodb: require "./mongodb"
|
||||||
|
http: require "./http"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue