message: Add metric tracking for MatrixHandler
diff: @@ -30,6 +30,9 @@ function MatrixHandler(ircBridge) {
  };
  this._memberTracker = null;
  + this.metrics = {
  + //domain => {"metricname" => value}
  + };
  }
  // ===== Matrix Invite Handling =====
  @@ -1481,6 +1484,22 @@ MatrixHandler.prototype._onUserQuery = Promise.coroutine(function*(req, userId)
  yield this.ircBridge.getMatrixUser(ircUser);
  });
  +MatrixHandler.prototype._incrementMetric = function(serverDomain, metricName) {
  + let metricSet = this.metrics[serverDomain];
  + if (metricSet === undefined) {
  + metricSet = this.metrics[serverDomain] = {
  +
  + };
  + }
  + if (metricSet[metricName] === undefined) {
  + metricSet[metricName] = 1;
  + }
  + else {
  + metricSet[metricName]++;
  + }
  + this.metrics[serverDomain] = metricSet;
  +}
  +
  // EXPORTS
  MatrixHandler.prototype.onMemberEvent = function(req, event, inviter, invitee) {
  @@ -1515,6 +1534,13 @@ MatrixHandler.prototype.onUserQuery = function(req, userId) {
  return reqHandler(req, this._onUserQuery(req, userId))
  };
  +MatrixHandler.prototype.getMetrics = function(serverDomain) {
  + if (this.metrics[serverDomain] === undefined) {
  + return null;
  + }
  + return this.metrics[serverDomain];
  +}
  +
  function reqHandler(req, promise) {
  return promise.then(function(res) {
  req.resolve(res);
  