class

Prometheus::Registry

Inherits Reference / Object

Registry stores and manages the collection of metrics.

The Registry is responsible for:

  • Storing metric instances
  • Ensuring metric names are unique
  • Collecting metrics in Prometheus text format

A default registry is provided via Prometheus.register, but you can also create your own registries if needed:

# Using default registry
Prometheus.register(metric)
output = Prometheus.collect

# Using custom registry
registry = Registry.new
registry.register(metric)
output = registry.collect

The registry ensures thread-safe access to metrics and provides proper synchronization for concurrent operations.

Constructors

default

Default global registry instance

Source

Instance methods

clear

Removes all metrics from the registry.

registry.clear
Source
collect(io : IO) : Nil
Source
collect

Collects all registered metrics and returns them in Prometheus text format.

The output format follows the Prometheus exposition format:

# HELP http_requests_total Total HTTP requests
# TYPE http_requests_total counter
http_requests_total{method="GET"} 42
output = registry.collect
puts output
Source
register(metric : Metric)

Registers a metric with this registry.

Each metric name must be unique within a registry. Attempting to register a metric with a name that's already in use will raise an ArgumentError.

counter = Counter.new("http_requests_total", "Total HTTP requests")
registry.register(counter)

Raises:

  • ArgumentError if a metric with the same name is already registered
Source
unregister(name : String)

Unregisters a metric by name.

registry.unregister("http_requests_total")
Source