class Prometheus::Registry

Overview

Registry stores and manages the collection of metrics.

The Registry is responsible for:

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.

Defined in:

registry.cr

Constructors

Instance Method Summary

Constructor Detail

def self.default : Registry #

Default global registry instance


Instance Method Detail

def clear #

Removes all metrics from the registry.

registry.clear

def collect : String #

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

def 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

def unregister(name : String) #

Unregisters a metric by name.

registry.unregister("http_requests_total")