Skip to content

Metrics & Telemetry

Record application metrics using counters, gauges, and histograms.

local metrics = require("metrics")
metrics.counter_inc("requests_total", {method = "POST"})
ParameterTypeDescription
namestringMetric name
labelstable?Label key-value pairs

Returns: boolean, error

metrics.counter_add("bytes_total", 1024, {direction = "out"})
ParameterTypeDescription
namestringMetric name
valuenumberValue to add
labelstable?Label key-value pairs

Returns: boolean, error

metrics.gauge_set("queue_depth", 42, {queue = "emails"})
ParameterTypeDescription
namestringMetric name
valuenumberCurrent value
labelstable?Label key-value pairs

Returns: boolean, error

metrics.gauge_inc("connections", {pool = "db"})
ParameterTypeDescription
namestringMetric name
labelstable?Label key-value pairs

Returns: boolean, error

metrics.gauge_dec("connections", {pool = "db"})
ParameterTypeDescription
namestringMetric name
labelstable?Label key-value pairs

Returns: boolean, error

metrics.histogram("duration_seconds", 0.123, {method = "GET"})
ParameterTypeDescription
namestringMetric name
valuenumberObserved value
labelstable?Label key-value pairs

Returns: boolean, error

ConditionKindRetryable
Collector not availableerrors.INTERNALno

See Error Handling for working with errors.