node-prometheus
    Preparing search index...

    Class Histogram

    A Prometheus Histogram metric. Counts observations in configurable buckets and provides sum + count.

    const hist = new Histogram({
    name: "response_time_seconds",
    description: "Response time in seconds",
    buckets: [0.1, 0.5, 1, 2, 5]
    });
    hist.observe(0.75);

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new Histogram.

      Parameters

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

        Configuration object.

        • Optionalbuckets?: number[]

          Optional bucket thresholds (default: []). +Inf always added.

        • Optionaldescription?: string

          Optional description.

        • Optionallabels?: Record<string, string>

          Optional default labels.

        • name: string

          Metric name.

      Returns Histogram

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

    The Prometheus metric type.

    Methods

    • Observes a value, updating buckets, sum, and count.

      Parameters

      • value: number

        The observed value.

      Returns void

    • Alias for observe().

      Parameters

      • value: number

        The observed value.

      Returns void

    • Resets all bucket counts, sum, and total count to zero.

      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.