Example 1
Example 1
import { MetricsPlugin } from '@setu-ts/metrics-plugin'; app.register(MetricsPlugin({ endpoint: '/metrics', httpMetrics: true, })); // Record metrics const metrics = ctx.services.get<IMetricsService>('metrics'); const counter = metrics.counter('my_counter', { help: 'My counter' }); counter.inc(1);
-
getValue(labels?: Readonly<Record<string, string>>): number
Gets the current value for a label set.
-
inc(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Increments the counter.
-
observe(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Records an observation — equivalent to
inc()for counters. -
valueEntries(): ReadonlyMap<string, CounterValue>
Gets all value entries with labels.
-
values(): ReadonlyMap<string, number>
Gets all values.
-
dec(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Decrements the gauge.
-
getValue(labels?: Readonly<Record<string, string>>): number
Gets the current value for a label set.
-
inc(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Increments the gauge.
-
observe(): voidvalue: number,labels?: Readonly<Record<string, string>>
Records an observation — equivalent to
set()for gauges. -
set(): voidvalue: number,labels?: Readonly<Record<string, string>>
Sets the gauge to a specific value.
-
valueEntries(): ReadonlyMap<string, GaugeValue>
Gets all value entries with labels.
-
values(): ReadonlyMap<string, number>
Gets all values.
-
buckets(): readonly number[]
The bucket boundaries.
-
getAllBucketCounts(): ReadonlyMap<>string,{ buckets: ReadonlyMap<number, number>; sum: number; count: number; labels?: Readonly<Record<string, string>>; }
Gets all bucket counts for all observed label sets.
-
getBucketCounts(labels?: Readonly<Record<string, string>>): ReadonlyMap<number, number>
Gets the bucket counts for a label set.
-
getCount(labels?: Readonly<Record<string, string>>): number
Gets the count for a label set.
-
getSum(labels?: Readonly<Record<string, string>>): number
Gets the sum for a label set.
-
observe(): voidvalue: number,labels?: Readonly<Record<string, string>>
Records an observation.
The metrics service — provides factory methods for creating metrics and rendering them in Prometheus format.
-
counter(): ICountername: string,options?: MetricOptions
Gets or creates a counter.
-
gauge(): IGaugename: string,options?: MetricOptions
Gets or creates a gauge.
-
get(name: string): IMetric | undefined
Gets a metric by name.
-
histogram(): IHistogramname: string,options?: MetricOptions
Gets or creates a histogram.
-
names(): readonly string[]
Gets all registered metric names.
-
register(): IMetricname: string,config: MetricConfig
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(): ISummaryname: string,options?: MetricOptions
Gets or creates a summary.
-
getAllQuantiles(): ReadonlyMap<>string,{ quantiles: ReadonlyMap<number, number>; sum: number; count: number; labels?: Readonly<Record<string, string>>; }
Gets all quantile data for all observed label sets.
-
getCount(labels?: Readonly<Record<string, string>>): number
Gets the count for a label set.
-
getQuantiles(labels?: Readonly<Record<string, string>>): ReadonlyMap<number, number>
Gets the quantile values for a label set.
-
getSampleCount(labels?: Readonly<Record<string, string>>): number
Gets the current sample window size.
-
getSum(labels?: Readonly<Record<string, string>>): number
Gets the sum for a label set.
-
observe(): voidvalue: number,labels?: Readonly<Record<string, string>>
Records an observation.
-
quantiles(): readonly number[]
The quantiles.
Creates a metrics plugin.
Monotonically increasing counter. observe / inc add a non-negative value.
-
inc(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Increments the counter.
Gauge: arbitrary set / inc / dec. observe sets the value.
-
dec(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Decrements the gauge.
-
inc(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Increments the gauge.
-
set(): voidvalue: number,labels?: Readonly<Record<string, string>>
Sets the gauge to a specific value.
Histogram: bucketed observation distribution plus sum and count.
-
buckets: readonly number[]
Upper bounds of the histogram buckets.
-
observe(): voidvalue: number,labels?: Readonly<Record<string, string>>
Records an observation (sample).
A registered metric.
-
help: string
Human-readable description.
-
name: string
Metric name (Prometheus naming conventions).
-
observe(): voidvalue?: number,labels?: Readonly<Record<string, string>>
Records an observation.
-
type: MetricType
The metric instrument kind.
Metrics service resolved via ctx.services.get<IMetricsService>('metrics').
-
counter(): ICountername: string,options?: MetricOptions
Gets or creates a counter.
-
gauge(): IGaugename: string,options?: MetricOptions
Gets or creates a gauge.
-
get(name: string): IMetric | undefined
Gets a metric by name.
-
histogram(): IHistogramname: string,options?: MetricOptions
Gets or creates a histogram.
-
summary(): ISummaryname: string,options?: MetricOptions
Gets or creates a summary.
Summary: per-quantile observations plus sum and count.
-
observe(): voidvalue: number,labels?: Readonly<Record<string, string>>
Records an observation (sample).
-
quantiles: readonly number[]
Configured quantiles.
Configuration for registering a metric.
-
buckets: readonly number[]
Histogram bucket boundaries (histogram metrics only).
-
help: string
Human-readable description (Prometheus
HELP). -
labels: readonly string[]
Label names attachable to observations.
-
type: MetricType
The metric instrument kind.
Ergonomic options for the typed factory methods. type is injected by the
method name; help defaults to the metric name.
-
buckets: readonly number[]
Histogram bucket boundaries (histogram metrics only).
-
help: string
Human-readable description (Prometheus
HELP). Defaults to the metric name. -
labels: readonly string[]
Label names attachable to observations.
-
maxSamples: number
Summary only: bounded sample-window size.
-
quantiles: readonly number[]
Summary quantiles (summary metrics only).
Plugin options for MetricsPlugin.
-
customMetrics: readonly NamedMetricConfig[]
Declarative metric definitions to pre-register.
-
defaultBuckets: readonly number[]
Default histogram bucket boundaries.
-
defaultMetrics: boolean
Enable built-in HTTP metrics.
-
defaultQuantiles: readonly number[]
Default summary quantiles.
-
endpoint: string
The scrape endpoint path.
-
excludePaths: readonly PathPattern[]
Request paths the HTTP metrics middleware skips entirely — no counter, histogram, or gauge is touched for them.
-
httpMetrics: boolean
Enable the metrics middleware for HTTP request tracking.
Usage
import * as Prometheus_metrics_plugin_for_Setu_TS___This_plugin_provides_____MetricsPlugin____The_plugin_factory____MetricsService____The_metrics_service_for_recording_metrics___Counter__Gauge__Histogram__Summary___Metric_instrument_classes____IMetricsService____ICounter____IGauge____IHistogram____ISummary____Type_contracts_from_common_ from "metrics-plugin/src/index.ts";