node-prometheus
    Preparing search index...

    Class Counter

    A Prometheus Counter metric. Represents a cumulative metric that only increases.

    const counter = new Counter({
    name: "http_requests_total",
    description: "Total HTTP requests",
    reader: () => [1234]
    });

    Hierarchy

    • ValueMetric<"counter">
      • Counter
    Index

    Constructors

    • Creates a new Counter.

      Parameters

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

        Configuration object.

      Returns Counter

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

    The Prometheus metric type.

    Methods

    • Increments the counter by a given value (convenience alias). Note: Since Counter uses a reader, this is just documentation — actual increment must be handled in the reader function or external state.

      Parameters

      • delta: number = 1

        Amount to increment by (default: 1).

      Returns void

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