node-prometheus
    Preparing search index...

    Class Metric<T>Abstract

    Base class for all Prometheus metrics. Handles common functionality like HELP/TYPE comments and label formatting.

    Type Parameters

    • T extends MetricType

      The metric type (e.g., 'gauge', 'counter').

    Hierarchy (View Summary)

    Index

    Properties

    description?: string

    Optional metric description (used in # HELP).

    labels?: Record<string, string>

    Default labels applied to all samples of this metric.

    name: string

    The sanitized metric name.

    type: T

    The Prometheus metric type.

    Methods

    • Serializes the metric to Prometheus exposition format.

      Returns Promise<string>

      A Promise resolving to the serialized string.

    • Sanitizes a metric name by removing or replacing invalid characters.

      Prometheus metric names must match [a-zA-Z_:][a-zA-Z0-9_:]* This removes hyphens, parens; replaces slashes and spaces with underscores.

      Parameters

      • Optionalinput: string

        The raw metric name.

      Returns string | undefined

      The cleaned metric name.

    • Concatenates multiple metrics into a single exposition string.

      Parameters

      • format: "prometheus" | "openmetrics" = 'prometheus'

        used to set the metric type

      • ...metrics: Metric<MetricType>[]

        The metrics to serialize.

      Returns Promise<string>

      A Promise resolving to the combined string.

    • Converts a label object to a Prometheus label string (e.g., {foo="bar"}).

      Parameters

      • Optionallabels: Record<string, string | number>

        The label key-value pairs.

      Returns string

      The formatted label string.