Skip to content

PrometheusMetrics

Formats Effect metrics for Prometheus.

This module reads metrics from the current Effect context and renders them in the Prometheus text format. It can also register a pull-based HTTP endpoint, such as /metrics, for Prometheus to scrape.

6 exports Added in v4.0.0 Source

Formatting

format

Added in v4.0.0 Source

Formats all metrics in the registry to Prometheus exposition format.

Signature

declare const format: (options?: FormatOptions) => Effect.Effect<string>;

formatUnsafe

Added in v4.0.0 Source

Formats all metrics in the registry to Prometheus exposition format synchronously.

When to use

Use when you already have access to the context and need low-level synchronous formatting.

See

  • format for effectful formatting from the current context

Signature

declare function formatUnsafe(context: Context<never>, options?: FormatOptions): string;

Layers

layerHttp

Added in v4.0.0 Source

Creates a Layer that registers a /metrics HTTP endpoint for Prometheus scraping.

Details

This layer automatically adds a GET route to your HTTP router that serves metrics in Prometheus exposition format. By default, the endpoint is registered at /metrics, but this can be customized via the path option.

Signature

declare function layerHttp(options?: HttpOptions): Layer<never, never, HttpRouter>;

Models

MetricNameMapper type

Added in v4.0.0 Source

A function that transforms metric names before formatting.

Signature

type MetricNameMapper = (name: string) => string;

Options

FormatOptions interface

Added in v4.0.0 Source

Options for formatting metrics.

Signature

interface FormatOptions {
  readonly metricNameMapper?: MetricNameMapper;
  readonly prefix?: string;
}

HttpOptions interface

Added in v4.0.0 Source

Options for exporting Prometheus metrics over HTTP.

Signature

interface HttpOptions extends FormatOptions {
  readonly path?: PathInput;
}