node-prometheus
    Preparing search index...

    Class Untyped

    A Prometheus Untyped metric. Used when metric type is unknown. Behaves like a Gauge.

    const metric = new Untyped({
    name: "some_unknown_metric",
    value: 42
    });
    metric.set(43);

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new Untyped metric.

      Parameters

      • config: {
            description?: string;
            labels?: Record<string, string>;
            name: string;
            value?: number | [number, number];
        }

        Configuration object.

        • Optionaldescription?: string

          Optional description.

        • Optionallabels?: Record<string, string>

          Optional default labels.

        • name: string

          Metric name.

        • Optionalvalue?: number | [number, number]

          Initial value or [value, timestamp] tuple.

      Returns Untyped

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

    The Prometheus metric type.

    Methods

    • Gets the current value and timestamp.

      Returns [number, number]

      [value, timestamp] tuple.

    • Sets the current value and timestamp.

      Parameters

      • value: number | [number, number]

        New value or [value, timestamp] tuple.

      Returns void

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