Gauge

A Gauge is a metric that represents a single numerical value that can go up and down.

Parameters

fullName

Full name of the metric.

help

Description of what the metric measures.

labelNames

List of label names.

unit

Optional unit of measurement.

clock

Clock used to set the current time as gauge value.

Types

Link copied to clipboard
inner class Child

Represents a labeled child of the gauge metric.

Properties

Link copied to clipboard

Full metric name (including any suffix or unit).

Link copied to clipboard

Description of the metric, explaining what it measures.

Link copied to clipboard

List of label names associated with this metric (e.g., "method", "status").

Link copied to clipboard
open override val name: String

The base name of the metric (without unit suffix).

Link copied to clipboard
open override val type: Collector.Type

The metric type (e.g., counter, gauge).

Link copied to clipboard

Unit of the metric (e.g., "seconds", "bytes").

Functions

Link copied to clipboard
fun clear()

Removes all labeled child instances and resets the no-label child (if applicable).

Link copied to clipboard

Collects all current samples from this gauge, across all label sets.

Link copied to clipboard
suspend fun dec()

Decrements the unlabeled gauge by 1.

suspend fun dec(amount: Double)

Decrements the unlabeled gauge by a specific amount.

Link copied to clipboard
fun get(): Double

Returns the current value of the unlabeled gauge.

Link copied to clipboard

Returns the simple class name of the Collector instance.

Link copied to clipboard
suspend fun inc()

Increments the unlabeled gauge by 1.

suspend fun inc(amount: Double)

Increments the unlabeled gauge by a specific amount.

Link copied to clipboard
fun labels(vararg labelValues: String): Gauge.Child

Retrieves or creates a Child associated with the given label values.

Link copied to clipboard
open override fun newChild(): Gauge.Child

Creates a new child instance. Called internally when a new label set is first seen.

Link copied to clipboard
suspend fun register(registry: CollectorRegistry = CollectorRegistry.defaultRegistry): Collector

Registers this collector in the given CollectorRegistry.

Link copied to clipboard
fun remove(vararg labelValues: String)

Removes the child instance associated with the given label values.

Link copied to clipboard
suspend fun set(amount: Double)

Sets the unlabeled gauge to a specific value.

Link copied to clipboard
suspend fun <T> Gauge.setDuration(block: () -> T): T

Measures the duration of a block and stores it in the unlabeled gauge.

Link copied to clipboard
suspend fun setToCurrentTime()

Sets the unlabeled gauge to the current Unix time in seconds.

Link copied to clipboard
inline suspend fun <T> Gauge.track(block: () -> T): T

Increments the unlabeled gauge while the block is running, and decrements it when the block completes.