InstrumentedThreadFactory

class InstrumentedThreadFactory @JvmOverloads constructor(delegate: ThreadFactory, name: String, help: String, registry: PrometheusRegistry = PrometheusRegistry.defaultRegistry) : ThreadFactory

A ThreadFactory decorator that instruments thread lifecycle with Prometheus metrics.

Tracks the number of threads created (counter), currently running (gauge), and terminated (counter). The exposed series are <name>_threads_created_total, <name>_threads_running and <name>_threads_terminated_total. In the Prometheus text format the counter families are also named with _total; in OpenMetrics they are named <name>_threads_created and <name>_threads_terminated. The counters' _created timestamp series are written only when the exporter enables created timestamps (io.prometheus.exporter.include_created_timestamps), which is off by default.

Parameters

delegate

the underlying ThreadFactory to delegate thread creation to.

name

the base name for the Prometheus metrics (see above for the series names).

help

the base help text for the Prometheus metrics.

registry

the registry to register the metrics with. Defaults to PrometheusRegistry.defaultRegistry; factories with the same name need separate registries.

Throws

if one of the metric names is already registered in registry. None of the three metrics is left registered in that case.

Constructors

Link copied to clipboard
constructor(delegate: ThreadFactory, name: String, help: String, registry: PrometheusRegistry = PrometheusRegistry.defaultRegistry)

Functions

Link copied to clipboard
open override fun newThread(runnable: Runnable): Thread?

Creates a thread through the delegate, counting it as created.