SimpleCollector

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.

This class provides common functionality for metric types like Counter and Gauge, including label management, child instance tracking, and sample collection.

Parameters

Child

The type of the labeled metric child (e.g., Counter.Child, Gauge.Child).

fullName

The full metric name (including suffix, if applicable).

help

A human-readable description of the metric's purpose.

labelNames

The list of label names (must be valid Prometheus identifiers).

unit

The unit of the metric (optional, e.g., "seconds").

Inheritors

Constructors

Link copied to clipboard
constructor(fullName: String, help: String, labelNames: List<String>, unit: String)

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
abstract val name: String

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

Link copied to clipboard
abstract 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 the current set of metric samples.

Link copied to clipboard

Returns the simple class name of the Collector instance.

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

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

Link copied to clipboard
abstract fun newChild(): 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.