class MetricsService
implements IMetricsService

The metrics service — provides factory methods for creating metrics and rendering them in Prometheus format.

Constructors

MetricsService(options?: MetricsServiceOptions)

Properties

readonly
names: readonly string[]

Gets all registered metric names.

Methods

counter(
name: string,
options?: MetricOptions
): ICounter

Gets or creates a counter.

gauge(
name: string,
options?: MetricOptions
): IGauge

Gets or creates a gauge.

get(name: string): IMetric | undefined

Gets a metric by name.

histogram(
name: string,
options?: MetricOptions
): IHistogram

Gets or creates a histogram.

register(
name: string,
config: MetricConfig
): IMetric

Registers a metric directly (for declarative registration).

render(): string

Renders all metrics in Prometheus text format.

snapshot(): readonly MetricSnapshot[]

Takes a snapshot of all metrics for rendering.

summary(
name: string,
options?: MetricOptions
): ISummary

Gets or creates a summary.

Usage

import { MetricsService } from "metrics-plugin/src/index.ts";