Crometheus::Registry
Inherits Reference / Object
The Registry class is responsible for aggregating samples from all
metrics and exposing data to Prometheus via an HTTP server.
Crometheus automatically instantiates a Registry for you, and
Metric registers with it by default. This means that for most
applications, this is all it takes to get an HTTP server up and
serving:
require "crometheus/registry"
Crometheus.default_registry.host = "0.0.0.0" # defaults to "localhost"
Crometheus.default_registry.port = 12345 # defaults to 5000
Crometheus.default_registry.start_server
Constructors
Creates a new Registry.
Will export standard process statistics by default by calling
Crometheus.make_standard_exports.
If you for some reason want to avoid this, set
include_standard_exports to false.
Instance methods
Returns an HTTP::Handler that generates metrics.
If path is configured, and does not match the context path,
passes through to the next handler instead.
Sets namespace to str, raising an ArgumentError if str is
not legal for a Prometheus metric name.
If non-nil, will only handle requests with a matching path.
Adds a Metric to this registry. The metric's samples will then
show up whenever the server is scraped. Metrics call #register
automatically in their constructors, so manual invocation is not
usually required.
Creates an HTTP::Server object bound to host and port
and begins serving metrics as per #get_handler.
Returns true once the server is stopped.
Returns false immediately if this registry is already serving.
Spawns a new fiber that serves HTTP connections on host and
port, then returns true. If the server is already running,
returns false without creating a new one.
#start_server is included for convenience, but does not do any
exception handling. Serious applications should use #run_server
(which runs in the current fiber) instead, or call #get_handler
if they need more control over HTTP features..
Stops the HTTP server, then returns true. If the server is not
running, returns false instead.
Removes a Metric from the registry. The Metric keeps its
state and can be re-registered later.