mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 04:13:41 -05:00
Use new metrics module
This commit is contained in:
parent
f511ebd4b6
commit
6011ce4783
3 changed files with 9 additions and 31 deletions
|
@ -7,7 +7,6 @@ RedisManager = require('./app/js/RedisManager.js')
|
||||||
UpdateManager = require('./app/js/UpdateManager.js')
|
UpdateManager = require('./app/js/UpdateManager.js')
|
||||||
Keys = require('./app/js/RedisKeyBuilder')
|
Keys = require('./app/js/RedisKeyBuilder')
|
||||||
redis = require('redis')
|
redis = require('redis')
|
||||||
metrics = require('./app/js/Metrics')
|
|
||||||
Errors = require "./app/js/Errors"
|
Errors = require "./app/js/Errors"
|
||||||
HttpController = require "./app/js/HttpController"
|
HttpController = require "./app/js/HttpController"
|
||||||
|
|
||||||
|
@ -15,9 +14,14 @@ redisConf = Settings.redis.web
|
||||||
rclient = redis.createClient(redisConf.port, redisConf.host)
|
rclient = redis.createClient(redisConf.port, redisConf.host)
|
||||||
rclient.auth(redisConf.password)
|
rclient.auth(redisConf.password)
|
||||||
|
|
||||||
|
Path = require "path"
|
||||||
|
Metrics = require "metrics-sharelatex"
|
||||||
|
Metrics.initialize("doc-updater")
|
||||||
|
Metrics.mongodb.monitor(Path.resolve(__dirname + "/node_modules/mongojs/node_modules/mongodb"), logger)
|
||||||
|
|
||||||
app = express()
|
app = express()
|
||||||
app.configure ->
|
app.configure ->
|
||||||
app.use(express.logger(':remote-addr - [:date] - :user-agent ":method :url" :status - :response-time ms'));
|
app.use(Metrics.http.monitor(logger));
|
||||||
app.use express.bodyParser()
|
app.use express.bodyParser()
|
||||||
app.use app.router
|
app.use app.router
|
||||||
|
|
||||||
|
@ -32,10 +36,6 @@ rclient.on "message", (channel, doc_key) ->
|
||||||
|
|
||||||
UpdateManager.resumeProcessing()
|
UpdateManager.resumeProcessing()
|
||||||
|
|
||||||
app.use (req, res, next)->
|
|
||||||
metrics.inc "http-request"
|
|
||||||
next()
|
|
||||||
|
|
||||||
app.get '/project/:project_id/doc/:doc_id', HttpController.getDoc
|
app.get '/project/:project_id/doc/:doc_id', HttpController.getDoc
|
||||||
app.post '/project/:project_id/doc/:doc_id', HttpController.setDoc
|
app.post '/project/:project_id/doc/:doc_id', HttpController.setDoc
|
||||||
app.post '/project/:project_id/doc/:doc_id/flush', HttpController.flushDocIfLoaded
|
app.post '/project/:project_id/doc/:doc_id/flush', HttpController.flushDocIfLoaded
|
||||||
|
@ -44,7 +44,7 @@ app.delete '/project/:project_id', HttpController.deleteProjec
|
||||||
app.post '/project/:project_id/flush', HttpController.flushProject
|
app.post '/project/:project_id/flush', HttpController.flushProject
|
||||||
|
|
||||||
app.get '/total', (req, res)->
|
app.get '/total', (req, res)->
|
||||||
timer = new metrics.Timer("http.allDocList")
|
timer = new Metrics.Timer("http.allDocList")
|
||||||
RedisManager.getCountOfDocsInMemory (err, count)->
|
RedisManager.getCountOfDocsInMemory (err, count)->
|
||||||
timer.done()
|
timer.done()
|
||||||
res.send {total:count}
|
res.send {total:count}
|
||||||
|
@ -71,7 +71,6 @@ shutdownCleanly = (signal) ->
|
||||||
process.exit()
|
process.exit()
|
||||||
, 10000
|
, 10000
|
||||||
|
|
||||||
|
|
||||||
port = Settings.internal?.documentupdater?.port or Settings.apis?.documentupdater?.port or 3003
|
port = Settings.internal?.documentupdater?.port or Settings.apis?.documentupdater?.port or 3003
|
||||||
app.listen port, "localhost", ->
|
app.listen port, "localhost", ->
|
||||||
logger.log("documentupdater-sharelatex server listening on port #{port}")
|
logger.log("documentupdater-sharelatex server listening on port #{port}")
|
||||||
|
|
|
@ -1,23 +1 @@
|
||||||
StatsD = require('lynx')
|
module.exports = require "metrics-sharelatex"
|
||||||
statsd = new StatsD('localhost', 8125, {on_error:->})
|
|
||||||
|
|
||||||
buildKey = (key)-> "doc-updater.#{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
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
"coffee-script": "1.4.0",
|
"coffee-script": "1.4.0",
|
||||||
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#master",
|
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#master",
|
||||||
"logger-sharelatex": "git+https://github.com/sharelatex/logger-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",
|
||||||
"sinon": "~1.5.2",
|
"sinon": "~1.5.2",
|
||||||
"mongojs": "0.9.11"
|
"mongojs": "0.9.11"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue