Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/rocketchat-lib/lib/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ RocketChat.callbacks.remove = function(hookName, id) {
RocketChat.callbacks.run = function(hook, item, constant) {
const callbacks = RocketChat.callbacks[hook];
if (callbacks && callbacks.length) {

let rocketchatHooksEnd;
if (Meteor.isServer) {
rocketchatHooksEnd = RocketChat.metrics.rocketchatHooks.startTimer({hook, callbacks_length: callbacks.length});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to have this as RocketChat.statsTracker :

  • hooks are each registered callback, i.e.: sendNotificationsOnMessage
  • callbacks are named callbacks, i.e.: beforeSaveMessage

}

let totalTime = 0;
const result = _.sortBy(callbacks, function(callback) {
return callback.priority || RocketChat.callbacks.priority.MEDIUM;
Expand Down Expand Up @@ -105,13 +111,19 @@ RocketChat.callbacks.run = function(hook, item, constant) {
}
return (typeof callbackResult === 'undefined') ? result : callbackResult;
}, item);

if (Meteor.isServer) {
rocketchatHooksEnd();
}

if (RocketChat.callbacks.showTotalTime === true) {
if (Meteor.isServer) {
RocketChat.statsTracker.timing('callbacks.totalTime', totalTime, [`hook:${ hook }`]);
} else {
console.log(`${ hook }:`, totalTime);
}
}

return result;
} else {
return item;
Expand Down
9 changes: 6 additions & 3 deletions packages/rocketchat-lib/server/lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ RocketChat.metrics.meteorMethods = new client.Summary({
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: 'summary of rocketchat callbacks count and time',
labelNames: ['hook', 'callback']
});
RocketChat.metrics.meteorMethods.observe(10);

RocketChat.metrics.rocketchatHooks = new client.Summary({
name: 'rocketchat_hooks',
help: 'summary of rocketchat hooks count and time',
labelNames: ['hook', 'callbacks_length']
});

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

RocketChat.metrics.meteorSubscriptions = new client.Summary({
name: 'rocketchat_meteor_subscriptions',
Expand Down