class Prometheus::Registry
- Prometheus::Registry
- Reference
- Object
Overview
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.
Defined in:
registry.crConstructors
-
.default : Registry
Default global registry instance
Instance Method Summary
-
#clear
Removes all metrics from the registry.
-
#collect : String
Collects all registered metrics and returns them in Prometheus text format.
-
#register(metric : Metric)
Registers a metric with this registry.
-
#unregister(name : String)
Unregisters a metric by name.
Constructor Detail
Instance Method Detail
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
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
Unregisters a metric by name.
registry.unregister("http_requests_total")