/** * RED metrics for nifra as an opt-in `.use(metrics())` plugin, exposed in Prometheus text format at * `/metrics`. Dependency-free and in-process: an atomic counter/gauge/histogram registry with a * Prometheus renderer, plus automatic per-request rate/errors/duration series labeled by the matched * route TEMPLATE (not the raw path, so `/users/:id` is one series, not one per id). * * import { metrics } from "@nifrajs/otel/metrics" * const app = server().use(metrics()).get("/users/:id", handler) * // GET /metrics → nifra_http_requests_total{method="GET",route="/users/:id",status="200"} 5 … * * `c` is not touched; apps that want custom app metrics create their own registry and pass it in * (`metrics({ registry })`), then register series on it - they render at the same `/metrics`. */ import { type IdentityPlugin } from "@nifrajs/core/server"; type Labels = Readonly>; /** A monotonically increasing counter (requests, errors). */ export declare class Counter { readonly name: string; readonly help: string; private readonly series; constructor(name: string, help: string); inc(labels?: Labels, by?: number): void; render(): string; } /** A value that can go up and down (in-flight requests, queue depth). */ export declare class Gauge { readonly name: string; readonly help: string; private readonly series; constructor(name: string, help: string); private at; inc(labels?: Labels, by?: number): void; dec(labels?: Labels, by?: number): void; set(labels: Labels, value: number): void; render(): string; } /** Latency-style distribution over fixed buckets (seconds). Renders Prometheus cumulative buckets. */ export declare class Histogram { readonly name: string; readonly help: string; private readonly series; private readonly buckets; constructor(name: string, help: string, buckets: readonly number[]); observe(value: number, labels?: Labels): void; render(): string; } /** A collection of metrics that renders one Prometheus exposition document. */ export declare class MetricsRegistry { private readonly counters; private readonly gauges; private readonly histograms; counter(name: string, help?: string): Counter; gauge(name: string, help?: string): Gauge; histogram(name: string, buckets: readonly number[], help?: string): Histogram; /** The Prometheus text exposition of every registered series. */ render(): string; } /** Create a standalone registry to register custom app metrics on, shared into `metrics({ registry })`. */ export declare function createMetricsRegistry(): MetricsRegistry; export interface MetricsOptions { /** Where to expose the Prometheus text. Default `/metrics`. This route is excluded from the metrics. */ readonly path?: string; /** Reuse a registry (so custom app metrics render alongside the RED series). Default: a fresh one. */ readonly registry?: MetricsRegistry; /** Histogram buckets in SECONDS for request duration. Default OpenTelemetry latency buckets. */ readonly buckets?: readonly number[]; } /** * Enable RED metrics + a `/metrics` Prometheus endpoint. Records `nifra_http_requests_total`, * `nifra_http_request_duration_seconds`, and `nifra_http_requests_in_flight`, labeled by method, * matched route template, and status. Apply once (named-plugin dedupe). */ export declare function metrics(options?: MetricsOptions): IdentityPlugin; export {}; //# sourceMappingURL=metrics.d.ts.map