encore.dev/metrics

Classes

Counter

A Counter tracks cumulative values that only increase. Use counters for metrics like request counts, errors, etc.

Constructors

Constructor

new Counter(name, cfg?): Counter

Parameters
name

string

cfg?

MetricConfig

Returns

Counter

Methods

increment()

increment(value?): void

Increment the counter by the given value (default 1).

Parameters
value?

number = 1

Returns

void

ref()

ref(): Counter

Returns

Counter


CounterGroup

A CounterGroup tracks counters with labels. Each unique combination of label values creates a separate counter time series.

Type Parameters

L

L extends Record\<keyof L, string | number | boolean>

The label interface (must have string/number/boolean fields) Note: Number values in labels are converted to integers using Math.floor().

Constructors

Constructor

new CounterGroup<L>(name, cfg?): CounterGroup<L>

Parameters
name

string

cfg?

MetricConfig

Returns

CounterGroup\<L>

Methods

ref()

ref(): CounterGroup<L>

Returns

CounterGroup\<L>

with()

with(labels): Counter

Get a counter for the given label values.

Note: Number values in labels are converted to integers using Math.floor().

Parameters
labels

L

Returns

Counter


Gauge

A Gauge tracks values that can go up or down. Use gauges for metrics like memory usage, active connections, temperature, etc.

Constructors

Constructor

new Gauge(name, cfg?): Gauge

Parameters
name

string

cfg?

MetricConfig

Returns

Gauge

Methods

ref()

ref(): Gauge

Returns

Gauge

set()

set(value): void

Set the gauge to the given value.

Parameters
value

number

Returns

void


GaugeGroup

Type Parameters

L

L extends Record\<keyof L, string | number | boolean>

Constructors

Constructor

new GaugeGroup<L>(name, cfg?): GaugeGroup<L>

Parameters
name

string

cfg?

MetricConfig

Returns

GaugeGroup\<L>

Methods

ref()

ref(): GaugeGroup<L>

Returns

GaugeGroup\<L>

with()

with(labels): Gauge

Get a gauge for the given label values.

Note: Number values in labels are converted to integers using Math.floor().

Parameters
labels

L

Returns

Gauge

Interfaces

MetricConfig