I saw in this question how to setup Hapi Server to monitor the delay in the event loop of Node.js.
But I would like to log every time the delay exceeds a threshold, instead of returning 503.
How could I do it?
According to the API reference, there is an 'load' property in the server instance that contains the information I want, but I don't know how to listen to the event (or if there is such event) triggered when the load is checked.
UPDATE:
Ok, I found out there is a 'log' event that is triggered "when the server rejects a request due to high load", according to this.
But I just want to log, I don't want to reject any requests, so this doesn't solve the problem.
What I have so far, which logs when requests are rejected, is this:
server.on('log', (event) => {
if (event.tags && event.tags.indexOf('load') > -1) {
console.error(`Event loop lag detected! Latency: ${event.data.eventLoopDelay} ms`);
}
});