MetricsFacade class serves as a facade to simplify metrics management across all services in an application. It leverages the prom-client library for metrics management and the express library to expose these metrics via an HTTP endpoint.

It accommodates working in cluster environments by optionally creating a new AggregatorRegistry to hold metrics from all worker nodes, in addition to a separate registry for application-specific metrics and the default prom-client registry. Thus, it can manage up to three different registries:

  1. Default prom-client registry for default metrics.
  2. Application-specific metrics registry.
  3. Cluster-wide metrics registry for environments running in a cluster.

Depending on the environment and the node type (primary or worker), it responds to metric requests by merging and presenting metrics from appropriate registries.

Hierarchy

  • EventEmitter
    • MetricsFacade

Implements

Constructors

Accessors

  • get componentId(): string
  • Returns string

    The application identifier

  • Returns { [link: string]: string }

    Links offered by this service

  • get name(): string
  • Returns string

    The application name

  • get registry(): Registry<"text/plain; version=0.0.4; charset=utf-8">
  • Returns Registry<"text/plain; version=0.0.4; charset=utf-8">

    The registry used by the aggregator

  • get router(): Router
  • Returns Router

    An Express router with access to metrics information

  • get status(): "pass" | "fail" | "warn"
  • Returns "pass" | "fail" | "warn"

    The health status of the component

Methods

  • Clears all metrics from the registry.

    Returns Promise<void>

  • Retrieves a single metric by name.

    Parameters

    • name: string

      The name of the metric.

    Returns undefined | Metric

    The metric or undefined if not found.

  • Retrieves a single metric value in JSON format.

    Parameters

    • name: string

      The name of the metric.

    Returns Promise<undefined | MetricObjectWithValues<MetricValue<string>>>

    A promise resolved with the metric object or undefined if not found.

  • Retrieves a single metric value in Prometheus format.

    Parameters

    • name: string

      The name of the metric.

    Returns Promise<string>

    A promise resolved with the metric value as a string.

  • Returns Promise<Response>

    Metrics in JSON format

  • Returns Promise<Response>

    Metrics in text/plain format

  • Placeholder for starting the metrics service.

    Returns Promise<void>

  • Placeholder for stopping the metrics service.

    Returns Promise<void>