Package-level declarations

Types

Link copied to clipboard
abstract class Collector(val fullName: String, val help: String, val labelNames: List<String> = emptyList(), val unit: String = "")

Abstract base class for all Prometheus metric collectors.

Link copied to clipboard

A thread-safe registry for Collector instances.

Link copied to clipboard

A Counter is a metric that only increases (monotonically), typically used for counting occurrences.

Link copied to clipboard

Builder class for creating Counter metrics.

Link copied to clipboard

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

Link copied to clipboard

Builder class for creating Gauge metrics.

Link copied to clipboard

A histogram metric that tracks the distribution of values over a set of buckets.

Link copied to clipboard
class HistogramBuilder(name: String, buckets: List<Double>? = null) : MetricBuilder<Histogram>

Builder class for creating Histogram metrics.

Link copied to clipboard
abstract class MetricBuilder<T : SimpleCollector<*>>

Base class for building SimpleCollector instances with a fluent and idiomatic DSL.

Link copied to clipboard

Exports Prometheus metrics from a CollectorRegistry in the Prometheus text exposition format.

Link copied to clipboard

A Prometheus text format encoder (version 0.0.4).

Link copied to clipboard
Link copied to clipboard
abstract class SimpleCollector<Child>(val fullName: String, val help: String, val labelNames: List<String>, val unit: String) : Collector

Abstract base class for Prometheus metric types that support labeled children.

Link copied to clipboard
Link copied to clipboard

A Summary is a metric that provides statistical information about observed values, including quantiles.

Link copied to clipboard

Builder class for creating Summary metrics.

Link copied to clipboard
class TimeWindowQuantiles(quantiles: Array<Quantiles.Quantile>, maxAgeSeconds: Long, ageBuckets: Int)
Link copied to clipboard
data class ValueHistogram(val sum: Double, val buckets: List<Double>, val created: Long)

Represents the current state of a histogram, including the sum of observed values, the cumulative counts for each bucket, and the creation timestamp.

Link copied to clipboard
data class ValueSummary(val count: Double, val sum: Double, val quantiles: Map<Double, Double>?, val created: Long)

Represents the current state of a summary, including the count, sum, quantiles, and creation timestamp.

Functions

Link copied to clipboard
fun counter(name: String, block: CounterBuilder.() -> Unit): Counter

DSL-style function to build and register a Counter using a CounterBuilder.

Link copied to clipboard
suspend fun <T> Counter.countExceptions(vararg exceptionTypes: KClass<out Throwable>, block: () -> T): T?
suspend fun <T> Counter.Child.countExceptions(vararg exceptionTypes: KClass<out Throwable>, block: () -> T): T?

Executes the given block and increments the counter if an exception of the specified types is thrown.

Link copied to clipboard

Ensures a given string is surrounded by double quotes, correcting partial quotes.

Link copied to clipboard
fun exponentialHistogramBuckets(name: String, block: HistogramBuilder.() -> Unit, start: Double, factor: Double, count: Int): Histogram

Creates a histogram with exponentially spaced buckets.

Link copied to clipboard
fun gauge(name: String, block: GaugeBuilder.() -> Unit): Gauge

DSL-style function to build and register a Gauge using a GaugeBuilder.

Link copied to clipboard

Returns the simple class name of the Collector instance.

Link copied to clipboard
fun getCurrentMillis(clock: Clock = Clock.System): Long

Returns the current Unix timestamp in milliseconds from the given Clock.

Link copied to clipboard
fun getCurrentSeconds(clock: Clock = Clock.System): Long

Returns the current Unix timestamp in seconds from the given Clock.

Link copied to clipboard
fun histogram(name: String, block: HistogramBuilder.() -> Unit): Histogram

A DSL-style function to create and register a Histogram using a HistogramBuilder. Creates a histogram with the specified name and configuration defined in the block.

Link copied to clipboard
fun histogramBuckets(name: String, block: HistogramBuilder.() -> Unit, buckets: List<Double>): Histogram

Creates a histogram with predefined buckets.

Link copied to clipboard
fun linearHistogramBuckets(name: String, block: HistogramBuilder.() -> Unit, start: Double, width: Double, count: Int): Histogram

Creates a histogram with linearly spaced buckets.

Link copied to clipboard
fun quantile(quantile: Double, error: Double = 0.01): Quantiles.Quantile

Creates a quantile for use in summaries.

Link copied to clipboard

Converts a variable number of quantiles into a list.

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.

suspend fun <T> Gauge.Child.setDuration(block: () -> T): T

Measures the duration of a block and stores it in the labeled Gauge.Child.

Link copied to clipboard
fun summary(name: String, block: SummaryBuilder.() -> Unit): Summary

Creates a summary without predefined quantiles.

Link copied to clipboard
fun summaryQuantiles(name: String, block: SummaryBuilder.() -> Unit, quantiles: List<Quantiles.Quantile>, maxAgeSeconds: Long = 60, ageBuckets: Int = 5): Summary

Creates a summary with predefined quantiles.

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.

inline suspend fun <T> Gauge.Child.track(block: () -> T): T

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