Skip to content

Commit

Permalink
Prometheus: Add metrics of REST API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed May 14, 2018
1 parent bb4ff6a commit eae40f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion packages/rocketchat-api/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ class API extends Restivus {
//Add a try/catch for each endpoint
const originalAction = endpoints[method].action;
endpoints[method].action = function _internalRouteActionHandler() {
const rocketchatRestApiEnd = RocketChat.metrics.rocketchatRestApi.startTimer({
method,
entrypoint: route
});
this.logger.debug(`${ this.request.method.toUpperCase() }: ${ this.request.url }`);
let result;
try {
Expand All @@ -155,7 +159,13 @@ class API extends Restivus {
return RocketChat.API.v1.failure(e.message, e.error);
}

return result ? result : RocketChat.API.v1.success();
result = result ? result : RocketChat.API.v1.success();

rocketchatRestApiEnd({
status: result.statusCode
});

return result;
};

for (const [name, helperMethod] of this.getHelperMethods()) {
Expand Down
13 changes: 10 additions & 3 deletions packages/rocketchat-lib/server/lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ RocketChat.metrics = {};

RocketChat.metrics.meteorMethods = new client.Summary({
name: 'meteor_methods',
help: 'metric_help',
help: 'summary of meteor methods count and time',
labelNames: ['method']
});
RocketChat.metrics.meteorMethods.observe(10);

RocketChat.metrics.rocketchatCallbacks = new client.Summary({
name: 'rocketchat_callbacks',
help: 'metric_help',
help: 'summary of rocketchat callbacks count and time',
labelNames: ['hook', 'callback']
});
RocketChat.metrics.meteorMethods.observe(10);

RocketChat.metrics.rocketchatRestApi = new client.Summary({
name: 'rocketchat_rest_api',
help: 'summary of rocketchat rest api count and time',
labelNames: ['method', 'entrypoint', 'status']
});
RocketChat.metrics.meteorMethods.observe(10);

RocketChat.metrics.meteorSubscriptions = new client.Counter({
name: 'meteor_subscriptions',
help: 'metric_help',
help: 'summary of meteor subscriptions count and time',
labelNames: ['subscription']
});

Expand Down

0 comments on commit eae40f9

Please sign in to comment.