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.
Formatting
Signature
declare const format: (options?: FormatOptions) => Effect.Effect<string>;formatUnsafe
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
formatfor effectful formatting from the current context
Signature
declare function formatUnsafe(context: Context<never>, options?: FormatOptions): string;Layers
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
A function that transforms metric names before formatting.
Signature
type MetricNameMapper = (name: string) => string;Options
FormatOptions interface
Options for formatting metrics.
Signature
interface FormatOptions {
readonly metricNameMapper?: MetricNameMapper;
readonly prefix?: string;
}HttpOptions interface
Options for exporting Prometheus metrics over HTTP.
Signature
interface HttpOptions extends FormatOptions {
readonly path?: PathInput;
}
Formats all metrics in the registry to Prometheus exposition format.