class

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

new(include_standard_exports = true)

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.

Source

Instance methods

get_handler

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.

Source
host

The host that the server should bind to. Defaults to "localhost".

Source
host=(host : String)

The host that the server should bind to. Defaults to "localhost".

Source
metrics

A list of all Metric objects being exposed by this registry.

Source
namespace

If non-empty, will be prefixed to all metric names, separated by an underscore.

Source
namespace=(str : String)

Sets namespace to str, raising an ArgumentError if str is not legal for a Prometheus metric name.

Source
path

If non-nil, will only handle requests with a matching path.

Source
path=(path : String | Regex | Nil)

If non-nil, will only handle requests with a matching path.

Source
port

The port that the server should bind to. Defaults to 5000.

Source
port=(port : Int32)

The port that the server should bind to. Defaults to 5000.

Source
register(metric)

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.

Source
run_server

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.

Source
start_server

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..

Source
stop_server

Stops the HTTP server, then returns true. If the server is not running, returns false instead.

Source
unregister(metric)

Removes a Metric from the registry. The Metric keeps its state and can be re-registered later.

Source