From 77f8696b99f64baf9f72ce0ff694e6d838abeaf8 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 17 May 2018 10:53:39 -0300 Subject: [PATCH] Prometheus: Add metric to track hooks time --- packages/rocketchat-lib/lib/callbacks.js | 12 ++++++++++++ packages/rocketchat-lib/server/lib/metrics.js | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-lib/lib/callbacks.js b/packages/rocketchat-lib/lib/callbacks.js index 3744491b0a3f1..a1a2fee708781 100644 --- a/packages/rocketchat-lib/lib/callbacks.js +++ b/packages/rocketchat-lib/lib/callbacks.js @@ -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; diff --git a/packages/rocketchat-lib/server/lib/metrics.js b/packages/rocketchat-lib/server/lib/metrics.js index a503c5f9b04a4..a4a7391bc5146 100644 --- a/packages/rocketchat-lib/server/lib/metrics.js +++ b/packages/rocketchat-lib/server/lib/metrics.js @@ -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',