class Crometheus::Registry
- Crometheus::Registry
- Reference
- Object
Overview
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
Defined in:
crometheus/registry.crConstructors
-
.new(include_standard_exports = true)
Creates a new
Registry.
Instance Method Summary
-
#get_handler
Returns an
HTTP::Handlerthat generates metrics. -
#host : String
The host that the server should bind to.
-
#host=(host : String)
The host that the server should bind to.
-
#metrics : Array(Crometheus::Metric)
A list of all
Metricobjects being exposed by this registry. -
#namespace : String
If non-empty, will be prefixed to all metric names, separated by an underscore.
-
#namespace=(str : String)
Sets
#namespacetostr, raising anArgumentErrorifstris not legal for a Prometheus metric name. -
#path : String | Regex | Nil
If non-nil, will only handle requests with a matching path.
-
#path=(path : String | Regex | Nil)
If non-nil, will only handle requests with a matching path.
-
#port : Int32
The port that the server should bind to.
-
#port=(port : Int32)
The port that the server should bind to.
-
#register(metric)
Adds a
Metricto this registry. -
#run_server
Creates an
HTTP::Serverobject bound to#hostand#portand begins serving metrics as per#get_handler. - #start_server
-
#stop_server
Stops the HTTP server, then returns
true. -
#unregister(metric)
Removes a
Metricfrom the registry.
Constructor Detail
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 Method Detail
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.
A list of all Metric objects being exposed by this registry.
If non-empty, will be prefixed to all metric names, separated by an underscore.
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.