@stephen-shopopop/node-metrics
    Preparing search index...

    A builder class for constructing and managing Prometheus metrics.

    The PrometheusBuild class allows you to create and register custom metrics, such as gauges, with an optional prefix for metric names. It maintains an internal registry of metrics and provides a method to output all registered metrics in the OpenMetrics text format.

    • The serviceName, if provided, is prepended to all metric labels.
    • The printRegistries method returns a Response object with all metrics formatted for Prometheus scraping.
    Index

    Constructors

    Properties

    serviceName?: `${string}-${string}`

    Methods

    • Generates a plain text representation of all registered Prometheus metrics and returns it as an HTTP response.

      The response body is constructed by flattening each metric's help, type, and value fields, joining them with newline characters. The response is returned with a Content-Type header set to text/plain; version=0.0.4; charset=utf-8, which is compatible with Prometheus exposition format.

      Returns Response

      An HTTP response containing the formatted metrics data.

    • Sets a counter metric with the specified name and value, optionally with a label. The counter is created with the provided parameters and registered with the current prefix.

      Parameters

      • name: string

        The name of the counter metric.

      • value: number

        The numeric value to set for the counter.

      • Optionallabel: string

        (Optional) A label to associate with the counter metric.

      Returns PrometheusBuild

    • Sets a gauge metric with the specified name and value, optionally with a label. The gauge is created with the provided parameters and registered with the current prefix.

      Parameters

      • name: string

        The name of the gauge metric.

      • value: number | { [key: string]: number }

        The numeric value to set for the gauge.

      • Optionallabel: string

        (Optional) A label to associate with the gauge metric.

      Returns PrometheusBuild