@stephen-shopopop/node-metrics
    Preparing search index...
    • Creates a Fastify plugin that monitors system metrics and responds with a 503 Service Unavailable status when the system is under pressure, as determined by the provided options and current metrics.

      Parameters

      • appName: Readonly<Partial<MiddlewareOptions>>

        The name of the application, formatted as ${string}-${string} (e.g., "service-order")

      Returns FastifyPluginCallback

      A Fastify plugin that checks system pressure and responds accordingly.

      When the system is detected to be under pressure, the plugin:

      • Notifies observers with the current metrics.
      • Sets the Retry-After header.
      • Responds with HTTP 503 Service Unavailable. Otherwise, it continues processing the request.
      import Fastify from 'fastify';
      import { underPressureFastifyPlugin } from '@stephen-shopopop/node-metrics';

      const fastify = Fastify();

      fastify.register(underPressureFastifyPlugin({
      sampleIntervalInMs: 1000,
      resolution: 10,
      webServerMetricsPort: 9090,
      maxEventLoopDelay: 1000,
      maxEventLoopUtilization: 0.9
      }));