mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Use new metrics package
This commit is contained in:
parent
628fb65bc3
commit
b29e94b4d5
7 changed files with 8 additions and 121 deletions
|
@ -3,6 +3,8 @@ logger = require 'logger-sharelatex'
|
|||
logger.initialize("web-sharelatex")
|
||||
logger.logger.serializers.user = require("./app/js/infrastructure/LoggerSerializers").user
|
||||
logger.logger.serializers.project = require("./app/js/infrastructure/LoggerSerializers").project
|
||||
metrics = require("metrics-sharelatex")
|
||||
metrics.initialize("web")
|
||||
Server = require("./app/js/infrastructure/Server")
|
||||
BackgroundTasks = require("./app/js/infrastructure/BackgroundTasks")
|
||||
Errors = require "./app/js/errors"
|
||||
|
|
|
@ -1,27 +1 @@
|
|||
StatsD = require('lynx')
|
||||
settings = require('settings-sharelatex')
|
||||
statsd = new StatsD('localhost', 8125, {on_error:->})
|
||||
|
||||
buildKey = (key)-> "web.#{process.env.NODE_ENV}.#{key}"
|
||||
|
||||
module.exports =
|
||||
set : (key, value, sampleRate = 1)->
|
||||
statsd.set buildKey(key), value, sampleRate
|
||||
|
||||
inc : (key, sampleRate = 1)->
|
||||
statsd.increment buildKey(key), sampleRate
|
||||
|
||||
timing: (key, timeSpan, sampleRate)->
|
||||
statsd.timing(key, timeSpan, sampleRate)
|
||||
|
||||
Timer : class
|
||||
constructor :(key, sampleRate = 1)->
|
||||
this.start = new Date()
|
||||
this.key = buildKey(key)
|
||||
done:->
|
||||
timeSpan = new Date - this.start
|
||||
statsd.timing(this.key, timeSpan, this.sampleRate)
|
||||
|
||||
gauge : (key, value, sampleRate = 1)->
|
||||
statsd.gauge key, value, sampleRate
|
||||
|
||||
module.exports = require("metrics-sharelatex")
|
|
@ -1,5 +0,0 @@
|
|||
require("./Monitor/MongoDB").monitor()
|
||||
|
||||
exports.logger = require("./Monitor/HTTP").logger
|
||||
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
settings = require("settings-sharelatex")
|
||||
logger = require "logger-sharelatex"
|
||||
os = require("os")
|
||||
metrics = require("../Metrics")
|
||||
|
||||
module.exports.logger = (req, res, next) ->
|
||||
startTime = new Date()
|
||||
end = res.end
|
||||
res.end = () ->
|
||||
end.apply(this, arguments)
|
||||
responseTime = new Date() - startTime
|
||||
routePath = req.route.path.toString().replace(/\//g, '-').slice(1)
|
||||
|
||||
processName = if settings.internal.web.name? then "web-#{settings.internal.web.name}" else "web"
|
||||
key = "#{os.hostname()}.#{processName}.#{routePath}".toLowerCase().trim()
|
||||
logger.log
|
||||
req:
|
||||
url: req.originalUrl || req.url
|
||||
method: req.method
|
||||
key:key
|
||||
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"]
|
||||
"response-time": responseTime
|
||||
"http request"
|
||||
next()
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
Connection = require("mongoose/node_modules/mongodb/lib/mongodb/connection/connection").Connection
|
||||
MongoReply = require("mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply").MongoReply
|
||||
Metrics = require("../Metrics")
|
||||
logger = require "logger-sharelatex"
|
||||
_ = require("underscore")
|
||||
|
||||
connectionMonitor =
|
||||
newConnection: (id, db) ->
|
||||
Metrics.inc "mongo-requests"
|
||||
@connections[id] =
|
||||
timer: new Metrics.Timer("mongo-request-times")
|
||||
db: db
|
||||
start: new Date()
|
||||
setTimeout (=> @connectionDone(id)), 60000
|
||||
|
||||
connectionDone: (id) ->
|
||||
|
||||
queryIsNoise = (query)->
|
||||
isNoise = false
|
||||
if query? && _.isObject(query)
|
||||
keys = _.keys(query)
|
||||
if keys[0] == "ismaster" or keys[0] == "ping"
|
||||
isNoise = true
|
||||
return isNoise
|
||||
|
||||
logItOut = (db)->
|
||||
logger.log
|
||||
request_id: db.requestId,
|
||||
query: db.query,
|
||||
collection: db.collectionName,
|
||||
"response-time": new Date() - start
|
||||
"mongo request"
|
||||
|
||||
|
||||
|
||||
if @connections[id]?
|
||||
@connections[id].timer.done()
|
||||
db = @connections[id].db
|
||||
start = @connections[id].start
|
||||
if !queryIsNoise(db.query)
|
||||
logItOut(db)
|
||||
delete @connections[id]
|
||||
|
||||
connections: {}
|
||||
|
||||
monkeyPatchMongo = () ->
|
||||
write = Connection::write
|
||||
Connection::write = (db) ->
|
||||
write.apply(this, arguments)
|
||||
connectionMonitor.newConnection db.requestId, db
|
||||
|
||||
parseHeader = MongoReply::parseHeader
|
||||
MongoReply::parseHeader = () ->
|
||||
parseHeader.apply this, arguments
|
||||
connectionMonitor.connectionDone this.responseTo
|
||||
|
||||
module.exports.monitor = monkeyPatchMongo
|
|
@ -1,3 +1,4 @@
|
|||
Path = require "path"
|
||||
express = require('express')
|
||||
Settings = require('settings-sharelatex')
|
||||
logger = require 'logger-sharelatex'
|
||||
|
@ -16,7 +17,8 @@ cookieParser = express.cookieParser(Settings.security.sessionSecret)
|
|||
oneDayInMilliseconds = 86400000
|
||||
ReferalConnect = require('../Features/Referal/ReferalConnect')
|
||||
|
||||
Monitor = require "./Monitor"
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongojs/node_modules/mongodb"), logger)
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongoose/node_modules/mongodb"), logger)
|
||||
|
||||
Settings.editorIsOpen ||= true
|
||||
|
||||
|
@ -69,7 +71,7 @@ app.configure 'production', ->
|
|||
logger.info "Production Enviroment"
|
||||
app.enable('view cache')
|
||||
|
||||
app.use Monitor.logger
|
||||
app.use metrics.http.monitor(logger)
|
||||
|
||||
app.use (req, res, next)->
|
||||
metrics.inc "http-request"
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"bufferedstream": "1.6.0",
|
||||
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#master",
|
||||
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#master",
|
||||
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#master",
|
||||
"soa-req-id": "git+https://github.com/sharelatex/soa-req-id.git#master",
|
||||
"fairy": "0.0.2",
|
||||
"node-uuid": "1.4.1",
|
||||
|
|
Loading…
Reference in a new issue