Skip to content
Snippets Groups Projects
Unverified Commit c2974202 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento Committed by GitHub
Browse files

Prometheus: Add metric to track hooks time (#10798)

parent d3446aad
No related merge requests found
......@@ -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});
}
let totalTime = 0;
const result = _.sortBy(callbacks, function(callback) {
return callback.priority || RocketChat.callbacks.priority.MEDIUM;
......@@ -105,6 +111,11 @@ 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 }`]);
......@@ -112,6 +123,7 @@ RocketChat.callbacks.run = function(hook, item, constant) {
console.log(`${ hook }:`, totalTime);
}
}
return result;
} else {
return item;
......
......@@ -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',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment