node-prometheus
    Preparing search index...

    Class Gauge

    A Prometheus Gauge metric. Represents a single numerical value that can arbitrarily go up and down.

    const gauge = new Gauge({
    name: "temperature_celsius",
    description: "Current temperature in Celsius",
    reader: () => [23.5]
    });

    Hierarchy

    • ValueMetric<"gauge">
      • Gauge
    Index

    Constructors

    • Creates a new Gauge.

      Parameters

      • config: {
            description?: string;
            labels?: Record<string, string>;
            name: string;
            reader: () => MaybePromise<ValueReaderResult[]>;
        }

        Configuration object.

      Returns Gauge

    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: "gauge"

    The Prometheus metric type.

    Methods

    • Returns Promise<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.