diff --git a/services/document-updater/app.coffee b/services/document-updater/app.coffee index ddc438f752..a52b26f500 100644 --- a/services/document-updater/app.coffee +++ b/services/document-updater/app.coffee @@ -7,7 +7,6 @@ RedisManager = require('./app/js/RedisManager.js') UpdateManager = require('./app/js/UpdateManager.js') Keys = require('./app/js/RedisKeyBuilder') redis = require('redis') -metrics = require('./app/js/Metrics') Errors = require "./app/js/Errors" HttpController = require "./app/js/HttpController" @@ -15,9 +14,14 @@ redisConf = Settings.redis.web rclient = redis.createClient(redisConf.port, redisConf.host) 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.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 app.router @@ -32,10 +36,6 @@ rclient.on "message", (channel, doc_key) -> UpdateManager.resumeProcessing() -app.use (req, res, next)-> - metrics.inc "http-request" - next() - 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/flush', HttpController.flushDocIfLoaded @@ -44,7 +44,7 @@ app.delete '/project/:project_id', HttpController.deleteProjec app.post '/project/:project_id/flush', HttpController.flushProject app.get '/total', (req, res)-> - timer = new metrics.Timer("http.allDocList") + timer = new Metrics.Timer("http.allDocList") RedisManager.getCountOfDocsInMemory (err, count)-> timer.done() res.send {total:count} @@ -71,7 +71,6 @@ shutdownCleanly = (signal) -> process.exit() , 10000 - port = Settings.internal?.documentupdater?.port or Settings.apis?.documentupdater?.port or 3003 app.listen port, "localhost", -> logger.log("documentupdater-sharelatex server listening on port #{port}") diff --git a/services/document-updater/app/coffee/Metrics.coffee b/services/document-updater/app/coffee/Metrics.coffee index 0b98550c0e..4bf5c6dba5 100644 --- a/services/document-updater/app/coffee/Metrics.coffee +++ b/services/document-updater/app/coffee/Metrics.coffee @@ -1,23 +1 @@ -StatsD = require('lynx') -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 - +module.exports = require "metrics-sharelatex" \ No newline at end of file diff --git a/services/document-updater/package.json b/services/document-updater/package.json index fbcad4abc1..25feab87d8 100644 --- a/services/document-updater/package.json +++ b/services/document-updater/package.json @@ -14,6 +14,7 @@ "coffee-script": "1.4.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", "sinon": "~1.5.2", "mongojs": "0.9.11" },