From e64b08fcbe0ed539d353e4b585a51a6b5c27e4d7 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 15 Mar 2016 14:04:37 +0000 Subject: [PATCH] add metrics for latexmk runs and errors --- app/coffee/CompileManager.coffee | 14 +++++++++++--- app/coffee/LatexRunner.coffee | 15 +++++++++++++-- package.json | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/coffee/CompileManager.coffee b/app/coffee/CompileManager.coffee index 82ac793..f333018 100644 --- a/app/coffee/CompileManager.coffee +++ b/app/coffee/CompileManager.coffee @@ -10,6 +10,7 @@ child_process = require "child_process" CommandRunner = require(Settings.clsi?.commandRunner or "./CommandRunner") DraftModeManager = require "./DraftModeManager" fs = require("fs") +os = require("os") module.exports = CompileManager = doCompile: (request, callback = (error, outputFiles) ->) -> @@ -38,10 +39,17 @@ module.exports = CompileManager = compiler: request.compiler timeout: request.timeout image: request.imageName - }, (error) -> + }, (error, output, stats) -> return callback(error) if error? - logger.log project_id: request.project_id, time_taken: Date.now() - timer.start, "done compile" - timer.done() + Metrics.inc("compiles") + for metric_key, metric_value of stats or {} + Metrics.count(metric_key, metric_value) + loadavg = os.loadavg?() + Metrics.gauge("load-avg", loadavg[0]) if loadavg? + ts = timer.done() + logger.log {project_id: request.project_id, time_taken: ts, stats:stats, loadavg:loadavg}, "done compile" + if stats?["latex-runs"] > 0 + Metrics.timing("run-compile-per-pass", ts / stats["latex-runs"]) OutputFileFinder.findOutputFiles request.resources, compileDir, (error, outputFiles) -> return callback(error) if error? diff --git a/app/coffee/LatexRunner.coffee b/app/coffee/LatexRunner.coffee index 169a216..1cd851b 100644 --- a/app/coffee/LatexRunner.coffee +++ b/app/coffee/LatexRunner.coffee @@ -27,9 +27,20 @@ module.exports = LatexRunner = else return callback new Error("unknown compiler: #{compiler}") - CommandRunner.run project_id, command, directory, image, timeout, callback + CommandRunner.run project_id, command, directory, image, timeout, (error, output) -> + return callback(error) if error? + runs = output?.stderr?.match(/^Run number \d+ of .*latex/mg)?.length or 0 + failed = if output?.stdout?.match(/^Latexmk: Errors/m)? then 1 else 0 + # counters from latexmk output + stats = {} + stats["latexmk-errors"] = failed + stats["latex-runs"] = runs + stats["latex-runs-with-errors"] = if failed then runs else 0 + stats["latex-runs-#{runs}"] = 1 + stats["latex-runs-with-errors-#{runs}"] = if failed then 1 else 0 + callback error, output, stats - _latexmkBaseCommand: [ "latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR"] + _latexmkBaseCommand: ["latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR"] _pdflatexCommand: (mainFile) -> LatexRunner._latexmkBaseCommand.concat [ diff --git a/package.json b/package.json index f215717..33560b5 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "request": "~2.21.0", "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.0.0", "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0", - "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.3.0", + "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.5.0", "sequelize": "^2.1.3", "wrench": "~1.5.4", "smoke-test-sharelatex": "git+https://github.com/sharelatex/smoke-test-sharelatex.git#v0.2.0",