Prometheus::Registry
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
Instance methods
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
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