An Express middleware function that monitors system pressure and responds accordingly.
app.use(underPressureExpressMiddleware({
sampleIntervalInMs: 1000,
resolution: 10,
webServerMetricsPort: 9090,
maxEventLoopDelay: 100,
maxEventLoopUtilization: 0.9,
retryAfter: 30
}));
Express middleware to monitor system metrics and respond with HTTP 503 when the system is under pressure.
This middleware periodically samples system metrics and, based on configurable thresholds, determines if the server is under excessive load. If so, it sends a 503 Service Unavailable response with a
Retry-After
header, otherwise it passes control to the next middleware.